diff --git a/public/profile.php b/public/profile.php index a35260e..29ffb91 100644 --- a/public/profile.php +++ b/public/profile.php @@ -15,7 +15,7 @@ use Misuzu\Users\Assets\UserImageAssetFileTooLargeException; 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'] : ''; $isEditing = !empty($_GET['edit']) && is_string($_GET['edit']) ? (bool)$_GET['edit'] : !empty($_POST) && is_array($_POST); diff --git a/src/Users/User.php b/src/Users/User.php index 89625f0..14d7f6b 100644 --- a/src/Users/User.php +++ b/src/Users/User.php @@ -806,6 +806,9 @@ class User implements HasRankInterface, JsonSerializable { }); } public static function byUsername(string $username): ?self { + if(empty($username)) + throw new UserNotFoundException; + $username = mb_strtolower($username); if(str_starts_with($username, 'flappyzor')) @@ -823,7 +826,11 @@ class User implements HasRankInterface, JsonSerializable { }); } public static function byEMailAddress(string $address): ?self { + if(empty($address)) + throw new UserNotFoundException; + $address = mb_strtolower($address); + return self::memoizer()->find(function($user) use ($address) { return mb_strtolower($user->getEmailAddress()) === $address; }, function() use ($address) { @@ -836,6 +843,9 @@ class User implements HasRankInterface, JsonSerializable { }); } public static function byUsernameOrEMailAddress(string $usernameOrAddress): self { + if(empty($usernameOrAddress)) + throw new UserNotFoundException; + $usernameOrAddressLower = mb_strtolower($usernameOrAddress); if(!str_contains($usernameOrAddressLower, '@') && str_starts_with($usernameOrAddressLower, 'flappyzor')) @@ -859,6 +869,9 @@ class User implements HasRankInterface, JsonSerializable { ->fetchObject(self::class); } public static function findForProfile($userIdOrName): ?self { + if(empty($userIdOrName)) + throw new UserNotFoundException; + $userIdOrNameLower = mb_strtolower($userIdOrName); if(str_starts_with($userIdOrNameLower, 'flappyzor'))