From f0fc0f257b16be3ca3eb5c0d4bc24c89fc09c6a2 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Thu, 14 Aug 2025 16:53:51 -0400 Subject: [PATCH] Update return types --- src/DragonKnight/Actions/Users.php | 113 +++++++++++++++-------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/src/DragonKnight/Actions/Users.php b/src/DragonKnight/Actions/Users.php index deb35e4..9d90ab8 100644 --- a/src/DragonKnight/Actions/Users.php +++ b/src/DragonKnight/Actions/Users.php @@ -45,7 +45,7 @@ class Users /** * Displays the login page, and processes login requests. */ - public static function login() + public static function login(): string|false { global $auth; @@ -75,7 +75,7 @@ class Users /** * Delete the current cookie and redirect to home. */ - public static function logout() + public static function logout(): void { global $auth; $auth->logout(); @@ -85,7 +85,7 @@ class Users /** * Register a new account. */ - public static function register() + public static function register(): string|false { if (isset($_POST['submit'])) { $form = validate($_POST, [ @@ -133,7 +133,7 @@ class Users return $page; } - public static function verify() + public static function verify(): string|false { if (isset($_POST['submit'])) { $u = trim($_POST['username'] ?? ''); @@ -153,7 +153,7 @@ class Users return render('verify'); } - public static function lostpassword() + public static function lostpassword(): string|false { if (isset($_POST['submit'])) { $e = trim($_POST['email'] ?? ''); @@ -177,66 +177,67 @@ class Users return render('lostpassword'); } - public static function changepassword() + public static function changepassword(): string|false { + if (! isset($_POST['submit'])) { + return false; + } + + $u = trim($_POST['username'] ?? ''); + $p = $_POST['password'] ?? ''; + $np = $_POST['new_password'] ?? ''; + $np2 = $_POST['new_password2'] ?? ''; + + $user = db()->query('SELECT password FROM users WHERE username=? LIMIT 1;', [$u]); + $user = $user->fetchArray(SQLITE3_ASSOC); + if ($user === false) { + exit('No account with that username.'); + } + + if (! password_verify($p, $user['password'])) { + exit('The old password you provided was incorrect.'); + } + + if (empty($np) || strlen($np) < 6) { + $errors[] = 'New password is required and must be at least 6 characters long.'; + } + + if ($np2 !== $np) { + $errors[] = 'Verify New Password must match.'; + } + + $realnewpass = password_hash($np, PASSWORD_ARGON2ID); + db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]); + global $auth; + $auth->logout(); - if (isset($_POST['submit'])) { - $u = trim($_POST['username'] ?? ''); - $p = $_POST['password'] ?? ''; - $np = $_POST['new_password'] ?? ''; - $np2 = $_POST['new_password2'] ?? ''; - - $user = db()->query('SELECT password FROM users WHERE username=? LIMIT 1;', [$u]); - $user = $user->fetchArray(SQLITE3_ASSOC); - if ($user === false) { - exit('No account with that username.'); - } - - if (! password_verify($p, $user['password'])) { - exit('The old password you provided was incorrect.'); - } - - if (empty($np) || strlen($np) < 6) { - $errors[] = 'New password is required and must be at least 6 characters long.'; - } - - if ($np2 !== $np) { - $errors[] = 'Verify New Password must match.'; - } - - $realnewpass = password_hash($np, PASSWORD_ARGON2ID); - db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]); - - $auth->logout(); - - return 'Your password was changed successfully.

You have been logged out of the game to avoid errors.

Please log back in to continue playing.'; - } + return 'Your password was changed successfully.

You have been logged out of the game to avoid errors.

Please log back in to continue playing.'; } - public static function settings() + public static function settings(): string|false { - if (is_post()) { - $form = validate($_POST, [ - 'game_skin' => ['in:0,1'], - ]); - if (! $form['valid']) { - exit(ul_from_validate_errors($form['errors'])); - } - $form = $form['data']; - - user()->game_skin = $form['game_skin']; - user()->save(); - - $alert = '
Settings updated
'; - - return $alert.render('settings'); + if (! is_post()) { + return render('settings'); } - return render('settings'); + $form = validate($_POST, [ + 'game_skin' => ['in:0,1'], + ]); + if (! $form['valid']) { + exit(ul_from_validate_errors($form['errors'])); + } + $form = $form['data']; + + user()->game_skin = $form['game_skin']; + user()->save(); + + $alert = '
Settings updated
'; + + return $alert.render('settings'); } - public static function sendpassemail($emailaddress, $password) + public static function sendpassemail($emailaddress, $password): bool { $email = <<