From 4fcc3ed7ca5ea5f3154086ac0ce7327b2386562e Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 27 Jan 2025 21:11:53 +0000 Subject: implement changing password --- routes/preferences.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'routes/preferences.php') diff --git a/routes/preferences.php b/routes/preferences.php index c7e27fc..cb07bd1 100644 --- a/routes/preferences.php +++ b/routes/preferences.php @@ -22,4 +22,30 @@ Router::getInstance()->mount('/fragment/preferences', function (array $args) { $saved = true; } render_template('preferences_form', ['user' => $user, 'saved' => $saved]); +}); + +Router::getInstance()->mount('/fragment/changePassword', function (array $args) { + $user = UserAccount::requireByCurrentSession(); + $error = null; + $success = false; + + if (isset($_POST['current'], $_POST['new'], $_POST['newRepeat'])) { + if (!$user->verifyPassword($_POST['current'])) { + $error = 'currentIncorrect'; + } elseif ($_POST['new'] != $_POST['newRepeat']) { + $error = 'doesntMatch'; + } else { + $user->passwordHash = defaults_password_hash($_POST['new']); + $user->save(); + $success = true; + } + } + + render_template('change_password_form', [ + 'error' => isset($error) ? __("changePassword.error.$error") : null, + 'success' => $success, + 'current' => $success ? null : ($_POST['current'] ?? null), + 'new' => $success ? null : ($_POST['new'] ?? null), + 'newRepeat' => $success ? null : ($_POST['newRepeat'] ?? null) + ]); }); \ No newline at end of file -- cgit v1.3