You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
PHTML
51 lines
1.6 KiB
PHTML
2 years ago
|
<?php
|
||
|
|
||
|
namespace App\Providers;
|
||
|
|
||
|
use Illuminate\Auth\EloquentUserProvider;
|
||
|
use Illuminate\Contracts\Support\Arrayable;
|
||
|
use Illuminate\Support\Str;
|
||
|
use App\Casts\EncryptFixed;
|
||
|
|
||
|
class CryptUserProvider extends EloquentUserProvider
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* Retrieve a user by the given credentials.
|
||
|
*
|
||
|
* @param array $credentials
|
||
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||
|
*/
|
||
|
public function retrieveByCredentials(array $credentials)
|
||
|
{
|
||
|
if (empty($credentials) || (count($credentials) === 1 && Str::contains($this->firstCredentialKey($credentials), 'password'))) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// First we will add each credential element to the query as a where clause.
|
||
|
// Then we can execute the query and, if we found a user, return it in a
|
||
|
// Eloquent Front "model" that will be utilized by the Guard instances.
|
||
|
$query = $this->newModelQuery();
|
||
|
|
||
|
$userModel = $this->createModel();
|
||
|
|
||
|
foreach ($credentials as $key => $value) {
|
||
|
if (Str::contains($key, 'password')) {
|
||
|
continue;
|
||
|
}
|
||
|
logger($key . " : " . $value);
|
||
|
if (Str::contains($key, ['email','phone','name'])) {
|
||
|
$query->whereCrypt($key, $value);
|
||
|
} else if ($value instanceof EncryptFixed) {
|
||
|
$query->whereCrypt($key, $value);
|
||
|
} else if (is_array($value) || $value instanceof Arrayable) {
|
||
|
$query->whereIn($key, $value);
|
||
|
} else {
|
||
|
$query->where($key, $value);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $query->first();
|
||
|
}
|
||
|
}
|