servnest/pg-act/auth/username.php
2023-05-02 18:02:08 +02:00

22 lines
573 B
PHP

<?php
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.'));
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.'));