33namespace Adldap \Laravel ;
44
55use Adldap \Laravel \Facades \Adldap ;
6- use Adldap \Schemas \ActiveDirectory ;
76use Adldap \Models \User ;
7+ use Adldap \Schemas \ActiveDirectory ;
8+ use Illuminate \Auth \EloquentUserProvider ;
9+ use Illuminate \Contracts \Auth \Authenticatable ;
10+ use Illuminate \Database \Eloquent \Model ;
811use Illuminate \Support \Arr ;
912use Illuminate \Support \Facades \Config ;
10- use Illuminate \Database \Eloquent \Model ;
11- use Illuminate \Contracts \Auth \Authenticatable ;
12- use Illuminate \Auth \EloquentUserProvider ;
1313
1414class AdldapAuthUserProvider extends EloquentUserProvider
1515{
1616 /**
17- * {@inheritDoc }
17+ * {@inheritdoc }
1818 */
1919 public function retrieveById ($ identifier )
2020 {
@@ -24,7 +24,7 @@ public function retrieveById($identifier)
2424 }
2525
2626 /**
27- * {@inheritDoc }
27+ * {@inheritdoc }
2828 */
2929 public function retrieveByToken ($ identifier , $ token )
3030 {
@@ -34,7 +34,7 @@ public function retrieveByToken($identifier, $token)
3434 }
3535
3636 /**
37- * {@inheritDoc }
37+ * {@inheritdoc }
3838 */
3939 public function retrieveByCredentials (array $ credentials )
4040 {
@@ -54,11 +54,11 @@ public function retrieveByCredentials(array $credentials)
5454 $ user = $ query ->first ();
5555
5656 // If the user is an Adldap User model instance.
57- if ($ user instanceof User) {
57+ if ($ user instanceof User) {
5858 // Retrieve the users login attribute.
5959 $ username = $ user ->{$ this ->getLoginAttribute ()};
6060
61- if (is_array ($ username )) {
61+ if (is_array ($ username )) {
6262 // We'll make sure we retrieve the users first username
6363 // attribute if it's contained in an array.
6464 $ username = Arr::get ($ username , 0 );
@@ -68,18 +68,18 @@ public function retrieveByCredentials(array $credentials)
6868 $ key = $ this ->getPasswordKey ();
6969
7070 // Try to log the user in.
71- if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
71+ if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
7272 // Login was successful, we'll create a new
7373 // Laravel model with the Adldap user.
7474 return $ this ->getModelFromAdldap ($ user , $ credentials [$ key ]);
7575 }
7676 }
7777
78- return null ;
78+ return ;
7979 }
8080
8181 /**
82- * Creates a local User from Active Directory
82+ * Creates a local User from Active Directory.
8383 *
8484 * @param User $user
8585 * @param string $password
@@ -107,7 +107,9 @@ protected function getModelFromAdldap(User $user, $password)
107107 $ model = $ this ->createModel ()->newQuery ()->where ([$ key => $ username ])->first ();
108108
109109 // Create the model instance of it isn't found.
110- if (!$ model ) $ model = $ this ->createModel ();
110+ if (!$ model ) {
111+ $ model = $ this ->createModel ();
112+ }
111113
112114 // Set the username and password in case
113115 // of changes in active directory.
@@ -120,7 +122,7 @@ protected function getModelFromAdldap(User $user, $password)
120122 // attributes on the model.
121123 $ model = $ this ->syncModelFromAdldap ($ user , $ model );
122124
123- if ($ this ->getBindUserToModel ()) {
125+ if ($ this ->getBindUserToModel ()) {
124126 $ model = $ this ->bindAdldapToModel ($ user , $ model );
125127 }
126128
@@ -139,10 +141,10 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
139141 {
140142 $ attributes = $ this ->getSyncAttributes ();
141143
142- foreach ($ attributes as $ modelField => $ adField ) {
144+ foreach ($ attributes as $ modelField => $ adField ) {
143145 $ adValue = $ user ->{$ adField };
144146
145- if (is_array ($ adValue )) {
147+ if (is_array ($ adValue )) {
146148 // If the AD Value is an array, we'll
147149 // retrieve the first value.
148150 $ adValue = Arr::get ($ adValue , 0 );
@@ -151,7 +153,7 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
151153 $ model ->{$ modelField } = $ adValue ;
152154 }
153155
154- if ($ model instanceof Model) {
156+ if ($ model instanceof Model) {
155157 $ model ->save ();
156158 }
157159
0 commit comments