123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Providers;
- use App\Repositories\Enums\CacheEnum;
- use Illuminate\Auth\EloquentUserProvider as BaseEloquentUserProvider;
- use Illuminate\Contracts\Support\Arrayable;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Str;
- class MultiGuardUserProvider extends BaseEloquentUserProvider
- {
-
- public function retrieveById($identifier)
- {
-
- $class_name = get_class($this->createModel());
- $cacheKey = CacheEnum::getCacheKey(CacheEnum::AUTHORIZATION_USER, $identifier) . ":api";
- $cacheExpireTime = CacheEnum::getCacheExpireTime(CacheEnum::AUTHORIZATION_USER);
- return Cache::remember($cacheKey, $cacheExpireTime, function () use ($identifier) {
- $model = $this->createModel();
- return $this->newModelQuery($model)
- ->where($model->getAuthIdentifierName(), $identifier)
- ->first();
- });
- }
-
- public function retrieveByCredentials(array $credentials)
- {
- if (empty($credentials) ||
- (count($credentials) === 1 &&
- Str::contains($this->firstCredentialKey($credentials), 'password'))) {
- return;
- }
-
-
-
- $query = $this->newModelQuery();
- foreach ($credentials as $key => $value) {
- if (Str::contains($key, 'password')) {
- continue;
- }
- if (is_array($value) || $value instanceof Arrayable) {
- $query->whereIn($key, $value);
- } else {
- $query->where($key, $value);
- }
- }
- return $query->first();
- }
- }
|