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