mirror of
https://github.com/standardebooks/web.git
synced 2025-07-09 16:20:27 -04:00
Allow getting users by name
This commit is contained in:
parent
75ef304824
commit
ab17e6af5d
2 changed files with 19 additions and 4 deletions
21
lib/User.php
21
lib/User.php
|
@ -278,7 +278,7 @@ class User{
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a `User` based on either a `UserId`, `Email`, or `Uuid`.
|
||||
* Get a `User` based on either a `UserId`, `Email`, or `Uuid`, or `Name`.
|
||||
*
|
||||
* @throws Exceptions\UserNotFoundException
|
||||
*/
|
||||
|
@ -293,11 +293,11 @@ class User{
|
|||
elseif(mb_stripos($identifier, '@') !== false){
|
||||
return User::GetByEmail($identifier);
|
||||
}
|
||||
elseif(mb_stripos($identifier, '-') !== false){
|
||||
elseif(preg_match('/^[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}$/', $identifier)){
|
||||
return User::GetByUuid($identifier);
|
||||
}
|
||||
else{
|
||||
throw new Exceptions\UserNotFoundException();
|
||||
return User::GetByName($identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,6 +316,21 @@ class User{
|
|||
', [$email], User::class)[0] ?? throw new Exceptions\UserNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\UserNotFoundException
|
||||
*/
|
||||
public static function GetByName(?string $name): User{
|
||||
if($name === null){
|
||||
throw new Exceptions\UserNotFoundException();
|
||||
}
|
||||
|
||||
return Db::Query('
|
||||
SELECT *
|
||||
from Users
|
||||
where Name = ?
|
||||
', [$name], User::class)[0] ?? throw new Exceptions\UserNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\UserNotFoundException
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue