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,30 +54,30 @@ 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 $ username = Arr::get ($ username , 0 );
6363 }
6464
6565 // Get the password input array key.
6666 $ key = $ this ->getPasswordKey ();
6767
6868 // Try to log the user in.
69- if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
69+ if ($ this ->authenticate ($ username , $ credentials [$ key ])) {
7070 // Login was successful, we'll create a new
7171 // Laravel model with the Adldap user.
7272 return $ this ->getModelFromAdldap ($ user , $ credentials [$ key ]);
7373 }
7474 }
7575
76- return null ;
76+ return ;
7777 }
7878
7979 /**
80- * Creates a local User from Active Directory
80+ * Creates a local User from Active Directory.
8181 *
8282 * @param User $user
8383 * @param string $password
@@ -105,7 +105,9 @@ protected function getModelFromAdldap(User $user, $password)
105105 $ model = $ this ->createModel ()->newQuery ()->where ([$ key => $ username ])->first ();
106106
107107 // Create the model instance of it isn't found.
108- if (!$ model ) $ model = $ this ->createModel ();
108+ if (!$ model ) {
109+ $ model = $ this ->createModel ();
110+ }
109111
110112 // Set the username and password in case
111113 // of changes in active directory.
@@ -118,7 +120,7 @@ protected function getModelFromAdldap(User $user, $password)
118120 // attributes on the model.
119121 $ model = $ this ->syncModelFromAdldap ($ user , $ model );
120122
121- if ($ this ->getBindUserToModel ()) {
123+ if ($ this ->getBindUserToModel ()) {
122124 $ model = $ this ->bindAdldapToModel ($ user , $ model );
123125 }
124126
@@ -137,10 +139,10 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
137139 {
138140 $ attributes = $ this ->getSyncAttributes ();
139141
140- foreach ($ attributes as $ modelField => $ adField ) {
142+ foreach ($ attributes as $ modelField => $ adField ) {
141143 $ adValue = $ user ->{$ adField };
142144
143- if (is_array ($ adValue )) {
145+ if (is_array ($ adValue )) {
144146 // If the AD Value is an array, we'll
145147 // retrieve the first value.
146148 $ adValue = Arr::get ($ adValue , 0 );
@@ -150,7 +152,7 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
150152 }
151153
152154 // Only save models that contain changes.
153- if ($ model instanceof Model && count ($ model ->getDirty ()) > 0 ) {
155+ if ($ model instanceof Model && count ($ model ->getDirty ()) > 0 ) {
154156 $ model ->save ();
155157 }
156158
0 commit comments