Update return types

This commit is contained in:
Valithor Obsidion 2025-08-14 16:53:51 -04:00
parent d40b826dfa
commit f0fc0f257b

View File

@ -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.<br><br>You have been logged out of the game to avoid errors.<br><br>Please <a href="/login">log back in</a> to continue playing.';
}
return 'Your password was changed successfully.<br><br>You have been logged out of the game to avoid errors.<br><br>Please <a href="/login">log back in</a> 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 = '<div class="alert">Settings updated</div>';
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 = '<div class="alert">Settings updated</div>';
return $alert.render('settings');
}
public static function sendpassemail($emailaddress, $password)
public static function sendpassemail($emailaddress, $password): bool
{
$email = <<<HTML
You or someone using your email address submitted a Lost Password application on the {env('game_name')} server, located at {env('game_url')}.
@ -251,7 +252,7 @@ class Users
return Mail::send_email($emailaddress, env('game_name').' Lost Password', $email);
}
public static function sendregmail($emailaddress, $vercode)
public static function sendregmail($emailaddress, $vercode): bool
{
$verurl = env('game_url').'/verify';