48 $this->middleware(
'guest', [
'except' =>
'logout']);
56 return redirect()->intended(
'dashboard');
60 return View::make(
'auth.login');
87 if ($ldap_server_cert_ignore) {
88 putenv(
'LDAPTLS_REQCERT=never');
92 $connection = ldap_connect($ldaphost) or die(
"Could not connect to {$ldaphost}");
94 ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
95 ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldapversion);
100 $ldapbind = ldap_bind($connection, $ldaprdn, $ldappass);
101 if (($results = @ldap_search($connection, $baseDn, $filterQuery)) !=
false) {
102 $entry = ldap_first_entry($connection, $results);
103 if (($userDn = @ldap_get_dn($connection, $entry)) !=
false) {
104 if (($isBound = ldap_bind($connection, $userDn, $password)) ==
"true") {
106 array_change_key_case(ldap_get_attributes($connection, $entry), CASE_LOWER)
113 LOG::error($e->getMessage());
115 ldap_close($connection);
136 $item[
"username"] = isset($ldapatttibutes[$ldap_result_username][0]) ? $ldapatttibutes[$ldap_result_username][0] :
"";
137 $item[
"employee_number"] = isset($ldapatttibutes[$ldap_result_emp_num][0]) ? $ldapatttibutes[$ldap_result_emp_num][0] :
"";
138 $item[
"lastname"] = isset($ldapatttibutes[$ldap_result_last_name][0]) ? $ldapatttibutes[$ldap_result_last_name][0] :
"";
139 $item[
"firstname"] = isset($ldapatttibutes[$ldap_result_first_name][0]) ? $ldapatttibutes[$ldap_result_first_name][0] :
"";
140 $item[
"email"] = isset($ldapatttibutes[$ldap_result_email][0]) ? $ldapatttibutes[$ldap_result_email][0] :
"" ;
143 if (!empty($item[
"username"])) {
147 'first_name' => $item[
"firstname"],
148 'last_name' => $item[
"lastname"],
149 'username' => $item[
"username"],
150 'email' => $item[
"email"],
151 'employee_num' => $item[
"employee_number"],
152 'password' => bcrypt(Input::get(
"password")),
154 'permissions' => [
"user" => 1],
155 'notes' =>
'Imported from LDAP' 157 User::save($newuser);
160 throw new Cartalyst\Sentry\Users\UserNotFoundException();
164 $credentials = array(
165 'username' => $item[
"username"],
166 'password' => Input::get(
"password")
179 $validator = $this->
validator(Input::all());
181 if ($validator->fails()) {
182 return Redirect::back()->withInput()->withErrors($validator);
188 LOG::debug(
"LDAP is enabled.");
190 $user = User::where(
'username',
'=', Input::get(
'username'))->whereNull(
'deleted_at')->first();
191 LOG::debug(
"Auth lookup complete");
198 LOG::debug(
"Local user ".Input::get(
'username').
" does not exist");
199 if ($userattr = $this->
ldap(Input::get(
'username'), Input::get(
'password'),
true)) {
200 LOG::debug(
"Creating local user from authenticated LDAP user.");
203 LOG::debug(
"User did not authenticate correctly against LDAP. No local user was created.");
209 LOG::debug(
"Local user ".Input::get(
'username').
" exists in database. Authenticating existing user against LDAP.");
211 if ($this->
ldap(Input::get(
'username'), Input::get(
'password'))) {
212 LOG::debug(
"Valid LDAP login. Updating the local data.");
213 $user = User::find($user->id);
214 $user->password = bcrypt(Input::get(
'password'));
215 $user->ldap_import = 1;
219 LOG::debug(
"User did not authenticate correctly against LDAP. Local user was not updated.");
227 LOG::debug(
"Authenticating user against database.");
229 if (!Auth::attempt(Input::only(
'username',
'password'), Input::get(
'remember-me', 0))) {
230 LOG::debug(
"Local authentication failed.");
232 return Redirect::back()->withInput()->with(
'error', trans(
'auth/message.account_not_found'));
236 $redirect = \Session::get(
'loginRedirect',
'home');
239 \Session::forget(
'loginRedirect');
242 return Redirect::to($redirect)->with(
'success', trans(
'auth/message.signin.success'));
245 return Redirect::back()->withInput()->withErrors($this->messageBag);
259 return Redirect::route(
'home')->with(
'success',
'You have successfully logged out!');
271 return Validator::make($data, [
272 'username' =>
'required',
273 'password' =>
'required',
validator(array $data)
Get a validator for an incoming registration request.
createUserFromLdap($ldapatttibutes)
Create user from LDAP attributes.
This controller handles authentication for the user, including local database users and LDAP users...
__construct()
Create a new authentication controller instance.
login()
Account sign in form processing.
ldap($username, $password, $returnUser=false)
Authenticates a user to LDAP.