2018-08-29 06:15:11 +00:00
|
|
|
<?php
|
|
|
|
|
2024-03-30 16:49:25 +00:00
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */
|
|
|
|
|
2018-08-29 06:15:11 +00:00
|
|
|
namespace App\Repositories;
|
|
|
|
|
2024-01-15 17:45:01 +00:00
|
|
|
use App\Models\User;
|
2024-03-31 17:19:03 +00:00
|
|
|
use App\Values\SSOUser;
|
2024-01-15 17:45:01 +00:00
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
class UserRepository extends Repository
|
2018-08-29 06:15:11 +00:00
|
|
|
{
|
2024-01-15 17:45:01 +00:00
|
|
|
public function getDefaultAdminUser(): User
|
|
|
|
{
|
|
|
|
return User::query()->where('is_admin', true)->oldest()->firstOrFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function findOneByEmail(string $email): ?User
|
|
|
|
{
|
2024-03-30 16:49:25 +00:00
|
|
|
return User::query()->firstWhere('email', $email);
|
|
|
|
}
|
|
|
|
|
2024-03-31 17:19:03 +00:00
|
|
|
public function findOneBySSO(SSOUser $ssoUser): ?User
|
2024-03-30 16:49:25 +00:00
|
|
|
{
|
|
|
|
// we prioritize the SSO ID over the email address, but still resort to the latter
|
|
|
|
return User::query()->firstWhere([
|
2024-03-31 17:19:03 +00:00
|
|
|
'sso_id' => $ssoUser->id,
|
|
|
|
'sso_provider' => $ssoUser->provider,
|
|
|
|
]) ?? $this->findOneByEmail($ssoUser->email);
|
2024-01-15 17:45:01 +00:00
|
|
|
}
|
2018-08-29 06:15:11 +00:00
|
|
|
}
|