|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\Overrides\Illuminate\Auth; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Illuminate\Auth\EloquentUserProvider as BaseEloquentUserProvider; |
|
9
|
|
|
|
|
10
|
|
|
class EloquentUserProvider extends BaseEloquentUserProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Retrieve a user by their unique identifier. |
|
14
|
|
|
* |
|
15
|
|
|
* @param mixed $identifier |
|
16
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
|
|
|
|
|
17
|
|
|
*/ |
|
18
|
|
|
public function retrieveById($identifier) |
|
19
|
|
|
{ |
|
20
|
|
|
$model = $this->createModel(); |
|
21
|
|
|
|
|
22
|
|
|
return $model->newQuery() |
|
23
|
|
|
->with(['roles' => function ($query) { |
|
24
|
|
|
$query->withoutGlobalScope('tenantable'); |
|
25
|
|
|
}]) |
|
26
|
|
|
->where($model->getAuthIdentifierName(), $identifier) |
|
27
|
|
|
->first(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Retrieve a user by their unique identifier and "remember me" token. |
|
32
|
|
|
* |
|
33
|
|
|
* @param mixed $identifier |
|
34
|
|
|
* @param string $token |
|
35
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
public function retrieveByToken($identifier, $token) |
|
38
|
|
|
{ |
|
39
|
|
|
$model = $this->createModel(); |
|
40
|
|
|
|
|
41
|
|
|
return $model->newQuery() |
|
42
|
|
|
->with(['roles' => function ($query) { |
|
43
|
|
|
$query->withoutGlobalScope('tenantable'); |
|
44
|
|
|
}]) |
|
45
|
|
|
->where($model->getAuthIdentifierName(), $identifier) |
|
46
|
|
|
->where($model->getRememberTokenName(), $token) |
|
47
|
|
|
->first(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Retrieve a user by the given credentials. |
|
52
|
|
|
* |
|
53
|
|
|
* @param array $credentials |
|
54
|
|
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
|
|
|
|
|
55
|
|
|
*/ |
|
56
|
|
|
public function retrieveByCredentials(array $credentials) |
|
57
|
|
|
{ |
|
58
|
|
|
if (empty($credentials)) { |
|
59
|
|
|
return; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// First we will add each credential element to the query as a where clause. |
|
63
|
|
|
// Then we can execute the query and, if we found a user, return it in a |
|
64
|
|
|
// Eloquent User "model" that will be utilized by the Guard instances. |
|
65
|
|
|
$query = $this->createModel()->newQuery()->with(['roles' => function ($query) { |
|
66
|
|
|
$query->withoutGlobalScope('tenantable'); |
|
67
|
|
|
}]); |
|
68
|
|
|
|
|
69
|
|
|
foreach ($credentials as $key => $value) { |
|
70
|
|
|
if (! Str::contains($key, 'password')) { |
|
71
|
|
|
$query->where($key, $value); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $query->first(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.