|
2 | 2 |
|
3 | 3 | namespace Adldap\Laravel; |
4 | 4 |
|
5 | | -use Adldap\Laravel\Facades\Adldap; |
6 | 5 | use Adldap\Laravel\Traits\ImportsUsers; |
7 | 6 | use Adldap\Models\User; |
8 | 7 | use Illuminate\Auth\EloquentUserProvider; |
@@ -40,40 +39,44 @@ public function retrieveByToken($identifier, $token) |
40 | 39 | */ |
41 | 40 | public function retrieveByCredentials(array $credentials) |
42 | 41 | { |
43 | | - // Get the search query for users only |
| 42 | + // Get the search query for users only. |
44 | 43 | $query = $this->newAdldapUserQuery(); |
45 | 44 |
|
46 | | - // Get the username input attributes |
47 | | - $attributes = $this->getUsernameAttribute(); |
48 | | - |
49 | | - // Get the input key |
50 | | - $key = key($attributes); |
51 | | - |
52 | | - // Filter the query by the username attribute |
53 | | - $query->whereEquals($attributes[$key], $credentials[$key]); |
54 | | - |
55 | | - // Retrieve the first user result |
56 | | - $user = $query->first(); |
| 45 | + // Make sure the connection is bound |
| 46 | + // before we try to utilize it. |
| 47 | + if ($query->getConnection()->isBound()) { |
| 48 | + // Get the username input attributes. |
| 49 | + $attributes = $this->getUsernameAttribute(); |
57 | 50 |
|
58 | | - // If the user is an Adldap User model instance. |
59 | | - if ($user instanceof User) { |
60 | | - // Retrieve the users login attribute. |
61 | | - $username = $user->{$this->getLoginAttribute()}; |
| 51 | + // Get the input key. |
| 52 | + $key = key($attributes); |
62 | 53 |
|
63 | | - if (is_array($username)) { |
64 | | - // We'll make sure we retrieve the users first username |
65 | | - // attribute if it's contained in an array. |
66 | | - $username = Arr::get($username, 0); |
67 | | - } |
| 54 | + // Filter the query by the username attribute. |
| 55 | + $query->whereEquals($attributes[$key], $credentials[$key]); |
68 | 56 |
|
69 | | - // Get the password input array key. |
70 | | - $key = $this->getPasswordKey(); |
| 57 | + // Retrieve the first user result. |
| 58 | + $user = $query->first(); |
71 | 59 |
|
72 | | - // Try to log the user in. |
73 | | - if ($this->authenticate($username, $credentials[$key])) { |
74 | | - // Login was successful, we'll create a new |
75 | | - // Laravel model with the Adldap user. |
76 | | - return $this->getModelFromAdldap($user, $credentials[$key]); |
| 60 | + // If the user is an Adldap User model instance. |
| 61 | + if ($user instanceof User) { |
| 62 | + // Retrieve the users login attribute. |
| 63 | + $username = $user->{$this->getLoginAttribute()}; |
| 64 | + |
| 65 | + if (is_array($username)) { |
| 66 | + // We'll make sure we retrieve the users first username |
| 67 | + // attribute if it's contained in an array. |
| 68 | + $username = Arr::get($username, 0); |
| 69 | + } |
| 70 | + |
| 71 | + // Get the password input array key. |
| 72 | + $key = $this->getPasswordKey(); |
| 73 | + |
| 74 | + // Try to log the user in. |
| 75 | + if ($this->authenticate($username, $credentials[$key])) { |
| 76 | + // Login was successful, we'll create a new |
| 77 | + // Laravel model with the Adldap user. |
| 78 | + return $this->getModelFromAdldap($user, $credentials[$key]); |
| 79 | + } |
77 | 80 | } |
78 | 81 | } |
79 | 82 |
|
|
0 commit comments