Fixed oversights that occur because of the empty username.

This commit is contained in:
flash 2023-04-29 21:57:21 +00:00
parent c06993ff1d
commit 6f679fc78c
2 changed files with 14 additions and 1 deletions

View file

@ -15,7 +15,7 @@ use Misuzu\Users\Assets\UserImageAssetFileTooLargeException;
require_once '../misuzu.php'; require_once '../misuzu.php';
$userId = !empty($_GET['u']) && is_string($_GET['u']) ? $_GET['u'] : 0; $userId = !empty($_GET['u']) && is_string($_GET['u']) ? trim($_GET['u']) : 0;
$profileMode = !empty($_GET['m']) && is_string($_GET['m']) ? (string)$_GET['m'] : ''; $profileMode = !empty($_GET['m']) && is_string($_GET['m']) ? (string)$_GET['m'] : '';
$isEditing = !empty($_GET['edit']) && is_string($_GET['edit']) ? (bool)$_GET['edit'] : !empty($_POST) && is_array($_POST); $isEditing = !empty($_GET['edit']) && is_string($_GET['edit']) ? (bool)$_GET['edit'] : !empty($_POST) && is_array($_POST);

View file

@ -806,6 +806,9 @@ class User implements HasRankInterface, JsonSerializable {
}); });
} }
public static function byUsername(string $username): ?self { public static function byUsername(string $username): ?self {
if(empty($username))
throw new UserNotFoundException;
$username = mb_strtolower($username); $username = mb_strtolower($username);
if(str_starts_with($username, 'flappyzor')) if(str_starts_with($username, 'flappyzor'))
@ -823,7 +826,11 @@ class User implements HasRankInterface, JsonSerializable {
}); });
} }
public static function byEMailAddress(string $address): ?self { public static function byEMailAddress(string $address): ?self {
if(empty($address))
throw new UserNotFoundException;
$address = mb_strtolower($address); $address = mb_strtolower($address);
return self::memoizer()->find(function($user) use ($address) { return self::memoizer()->find(function($user) use ($address) {
return mb_strtolower($user->getEmailAddress()) === $address; return mb_strtolower($user->getEmailAddress()) === $address;
}, function() use ($address) { }, function() use ($address) {
@ -836,6 +843,9 @@ class User implements HasRankInterface, JsonSerializable {
}); });
} }
public static function byUsernameOrEMailAddress(string $usernameOrAddress): self { public static function byUsernameOrEMailAddress(string $usernameOrAddress): self {
if(empty($usernameOrAddress))
throw new UserNotFoundException;
$usernameOrAddressLower = mb_strtolower($usernameOrAddress); $usernameOrAddressLower = mb_strtolower($usernameOrAddress);
if(!str_contains($usernameOrAddressLower, '@') && str_starts_with($usernameOrAddressLower, 'flappyzor')) if(!str_contains($usernameOrAddressLower, '@') && str_starts_with($usernameOrAddressLower, 'flappyzor'))
@ -859,6 +869,9 @@ class User implements HasRankInterface, JsonSerializable {
->fetchObject(self::class); ->fetchObject(self::class);
} }
public static function findForProfile($userIdOrName): ?self { public static function findForProfile($userIdOrName): ?self {
if(empty($userIdOrName))
throw new UserNotFoundException;
$userIdOrNameLower = mb_strtolower($userIdOrName); $userIdOrNameLower = mb_strtolower($userIdOrName);
if(str_starts_with($userIdOrNameLower, 'flappyzor')) if(str_starts_with($userIdOrNameLower, 'flappyzor'))