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