|
13 | 13 | class AdldapAuthUserProvider extends EloquentUserProvider
|
14 | 14 | {
|
15 | 15 | /**
|
16 |
| - * Retrieve a user by their unique identifier. |
17 |
| - * |
18 |
| - * @param mixed $identifier |
19 |
| - * |
20 |
| - * @return Authenticatable|null |
| 16 | + * {@inheritDoc} |
21 | 17 | */
|
22 | 18 | public function retrieveById($identifier)
|
23 | 19 | {
|
24 | 20 | $model = parent::retrieveById($identifier);
|
25 | 21 |
|
26 |
| - if ($model instanceof Authenticatable) { |
27 |
| - $attributes = $this->getUsernameAttribute(); |
28 |
| - |
29 |
| - $key = key($attributes); |
30 |
| - |
31 |
| - $query = Adldap::users()->search(); |
32 |
| - |
33 |
| - $query->whereEquals($attributes[$key], $model->{$key}); |
34 |
| - |
35 |
| - $user = $query->first(); |
| 22 | + return $this->discoverAdldapFromModel($model); |
| 23 | + } |
36 | 24 |
|
37 |
| - if ($user instanceof User && $this->getBindUserToModel()) { |
38 |
| - $model = $this->bindAdldapToModel($user, $model); |
39 |
| - } |
40 |
| - } |
| 25 | + /** |
| 26 | + * {@inheritDoc} |
| 27 | + */ |
| 28 | + public function retrieveByToken($identifier, $token) |
| 29 | + { |
| 30 | + $model = parent::retrieveByToken($identifier, $token); |
41 | 31 |
|
42 |
| - return $model; |
| 32 | + return $this->discoverAdldapFromModel($model); |
43 | 33 | }
|
44 | 34 |
|
45 | 35 | /**
|
46 |
| - * Retrieve a user by the given credentials. |
47 |
| - * |
48 |
| - * @param array $credentials |
49 |
| - * |
50 |
| - * @return Authenticatable|null |
| 36 | + * {@inheritDoc} |
51 | 37 | */
|
52 | 38 | public function retrieveByCredentials(array $credentials)
|
53 | 39 | {
|
@@ -146,6 +132,35 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
|
146 | 132 | return $model;
|
147 | 133 | }
|
148 | 134 |
|
| 135 | + /** |
| 136 | + * Retrieves the Adldap User model from the |
| 137 | + * specified Laravel model. |
| 138 | + * |
| 139 | + * @param mixed $model |
| 140 | + * |
| 141 | + * @return null|Authenticatable |
| 142 | + */ |
| 143 | + protected function discoverAdldapFromModel($model) |
| 144 | + { |
| 145 | + if ($model instanceof Authenticatable && $this->getBindUserToModel()) { |
| 146 | + $attributes = $this->getUsernameAttribute(); |
| 147 | + |
| 148 | + $key = key($attributes); |
| 149 | + |
| 150 | + $query = Adldap::users()->search(); |
| 151 | + |
| 152 | + $query->whereEquals($attributes[$key], $model->{$key}); |
| 153 | + |
| 154 | + $user = $query->first(); |
| 155 | + |
| 156 | + if ($user instanceof User) { |
| 157 | + $model = $this->bindAdldapToModel($user, $model); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + return $model; |
| 162 | + } |
| 163 | + |
149 | 164 | /**
|
150 | 165 | * Binds the Adldap User instance to the Eloquent model instance
|
151 | 166 | * by setting its `adldapUser` public property.
|
|
0 commit comments