This controller handles authentication for the user, including local database users and LDAP users.
More...
|
| validator (array $data) |
| Get a validator for an incoming registration request. More...
|
|
This controller handles authentication for the user, including local database users and LDAP users.
- Todo:
- Move LDAP methods into user model for better separation of concerns.
- Author
- [A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
- Version
- v1.0
Definition at line 26 of file AuthController.php.
App\Http\Controllers\Auth\AuthController::__construct |
( |
| ) |
|
Create a new authentication controller instance.
- Returns
- void
Definition at line 46 of file AuthController.php.
48 $this->middleware(
'guest', [
'except' =>
'logout']);
App\Http\Controllers\Auth\AuthController::createUserFromLdap |
( |
|
$ldapatttibutes | ) |
|
Create user from LDAP attributes.
- Parameters
-
- Returns
- array|bool
Definition at line 125 of file AuthController.php.
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")
App\Http\Controllers\Auth\AuthController::ldap |
( |
|
$username, |
|
|
|
$password, |
|
|
|
$returnUser = false |
|
) |
| |
Authenticates a user to LDAP.
- Parameters
-
| $username | |
| $password | |
bool | false | $returnUser | |
- Returns
- bool true if the username and/or password provided are valid false if the username and/or password provided are invalid array of ldap_attributes if $returnUser is true
Definition at line 74 of file AuthController.php.
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); 99 // binding to ldap server 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) 112 } catch (Exception $e) { 113 LOG::error($e->getMessage()); 115 ldap_close($connection);
App\Http\Controllers\Auth\AuthController::login |
( |
| ) |
|
Account sign in form processing.
- Returns
- Redirect
Definition at line 177 of file AuthController.php.
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);
validator(array $data)
Get a validator for an incoming registration request.
createUserFromLdap($ldapatttibutes)
Create user from LDAP attributes.
ldap($username, $password, $returnUser=false)
Authenticates a user to LDAP.
App\Http\Controllers\Auth\AuthController::logout |
( |
| ) |
|
Logout page.
- Returns
- Redirect
Definition at line 253 of file AuthController.php.
259 return Redirect::route(
'home')->with(
'success',
'You have successfully logged out!');
App\Http\Controllers\Auth\AuthController::showLoginForm |
( |
| ) |
|
Definition at line 52 of file AuthController.php.
56 return redirect()->intended(
'dashboard');
60 return View::make(
'auth.login');
App\Http\Controllers\Auth\AuthController::validator |
( |
array |
$data | ) |
|
|
protected |
Get a validator for an incoming registration request.
- Parameters
-
- Returns
Definition at line 269 of file AuthController.php.
271 return Validator::make($data, [
272 'username' =>
'required',
273 'password' =>
'required',
App\Http\Controllers\Auth\AuthController::$redirectTo = '/' |
|
protected |
App\Http\Controllers\Auth\AuthController::$username = 'username' |
|
protected |
The documentation for this class was generated from the following file: