mirror of
https://github.com/koel/koel
synced 2024-11-28 06:50:27 +00:00
30 lines
800 B
PHP
30 lines
800 B
PHP
<?php
|
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\User;
|
|
use App\Values\SSOUser;
|
|
|
|
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);
|
|
}
|
|
}
|