aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
authorwinter2025-01-27 21:11:53 +0000
committerwinter2025-01-27 21:11:53 +0000
commit4fcc3ed7ca5ea5f3154086ac0ce7327b2386562e (patch)
tree55f8caf30a56a83619ab153c942d685a1078a587 /routes
parent78536f774cacece20c22c1b26a7c4840d9e10794 (diff)
implement changing password
Diffstat (limited to 'routes')
-rw-r--r--routes/preferences.php26
1 files changed, 26 insertions, 0 deletions
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