koel/app/Repositories/UserRepository.php

31 lines
800 B
PHP
Raw Normal View History

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;
use App\Models\User;
use App\Values\SSOUser;
2022-07-29 06:47:10 +00:00
class UserRepository extends Repository
2018-08-29 06:15:11 +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);
}
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([
'sso_id' => $ssoUser->id,
'sso_provider' => $ssoUser->provider,
]) ?? $this->findOneByEmail($ssoUser->email);
}
2018-08-29 06:15:11 +00:00
}