Enhance db_get_user to find user by email or username

Updated db_get_user function to allow searching by email in addition to username.
This commit is contained in:
Naiel
2026-03-07 20:25:13 +01:00
committed by GitHub
parent f1ac55f359
commit 378515d28a

View File

@@ -108,9 +108,15 @@ function db_get_all_config(): array
// ── User helpers ──────────────────────────────────────────────────────────────
/** Find a user by username (always lower-cased). Returns DB row or null. */
/** Find a user by username or email (always lower-cased). Returns DB row or null. */
function db_get_user(string $username): ?array
{
if (str_contains($username, "@")) {
$stmt = db()->prepare('SELECT * FROM users WHERE email = ?');
$stmt->execute([strtolower($username)]);
$row = $stmt->fetch();
return $row !== false ? $row : null;
}
$stmt = db()->prepare('SELECT * FROM users WHERE username = ?');
$stmt->execute([strtolower($username)]);
$row = $stmt->fetch();