mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
33 lines
837 B
PHP
33 lines
837 B
PHP
<?php
|
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\User;
|
|
use App\Values\SSOUser;
|
|
|
|
/**
|
|
* @extends Repository<User>
|
|
*/
|
|
class UserRepository extends Repository
|
|
{
|
|
public function getDefaultAdminUser(): User
|
|
{
|
|
return User::query()->where('is_admin', true)->oldest()->firstOrFail();
|
|
}
|
|
|
|
public function findOneByEmail(string $email): ?User
|
|
{
|
|
return User::query()->firstWhere('email', $email);
|
|
}
|
|
|
|
public function findOneBySSO(SSOUser $ssoUser): ?User
|
|
{
|
|
// we prioritize the SSO ID over the email address, but still resort to the latter
|
|
return User::query()->firstWhere([
|
|
'sso_id' => $ssoUser->id,
|
|
'sso_provider' => $ssoUser->provider,
|
|
]) ?? $this->findOneByEmail($ssoUser->email);
|
|
}
|
|
}
|