1 | <?php |
||
2 | |||
3 | namespace Terranet\Administrator; |
||
4 | |||
5 | use Illuminate\Auth\EloquentUserProvider; |
||
6 | use Terranet\Administrator\Traits\CallableTrait; |
||
7 | |||
8 | /** |
||
9 | * Class AuthUserProvider. |
||
10 | */ |
||
11 | class AuthUserProvider extends EloquentUserProvider |
||
12 | { |
||
13 | use CallableTrait; |
||
14 | |||
15 | public function retrieveByCredentials(array $credentials) |
||
16 | { |
||
17 | // First we will add each credential element to the query as a where clause. |
||
18 | // Then we can execute the query and, if we found a user, return it in a |
||
19 | // Eloquent User "model" that will be utilized by the Guard instances. |
||
20 | $query = $this->createModel()->newQuery(); |
||
21 | |||
22 | foreach ($credentials as $key => $value) { |
||
23 | if (!str_contains($key, 'password')) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
24 | // handle closures |
||
25 | $value = $this->retrieveValue($value); |
||
26 | |||
27 | $query = \call_user_func_array([$query, $this->searchMethod($value)], [$key, $value]); |
||
28 | } |
||
29 | } |
||
30 | |||
31 | return $query->first(); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param $value |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function searchMethod($value) |
||
40 | { |
||
41 | return \is_array($value) ? 'whereIn' : 'where'; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param $value |
||
46 | * |
||
47 | * @return mixed |
||
48 | */ |
||
49 | protected function retrieveValue($value) |
||
50 | { |
||
51 | if (\is_callable($value)) { |
||
52 | $value = $this->callback($value); |
||
53 | } |
||
54 | |||
55 | return $value; |
||
56 | } |
||
57 | } |
||
58 |