servnest/pg-act/auth/username.php

23 lines
598 B
PHP
Raw Normal View History

2023-07-17 19:15:18 +00:00
<?php declare(strict_types=1);
checkUsernameFormat($_POST['new-username']);
if (checkPassword($_SESSION['id'], $_POST['current-password']) !== true)
output(403, _('Wrong current password.'));
$username = hashUsername($_POST['new-username']);
if (usernameExists($username) !== false)
output(403, _('This username is already taken.'));
2023-04-28 13:39:05 +00:00
rateLimit();
DB->prepare('UPDATE users SET username = :username WHERE id = :id')
->execute([':username' => $username, ':id' => $_SESSION['id']]);
setupDisplayUsername($_POST['new-username']);
redir('auth/username');
output(200, _('Username updated.'));