diff options
| -rw-r--r-- | locale/en_GB.json | 8 | ||||
| -rw-r--r-- | routes/preferences.php | 26 | ||||
| -rw-r--r-- | templates/change_password_form.php | 24 | ||||
| -rw-r--r-- | templates/preferences_page.php | 3 |
4 files changed, 61 insertions, 0 deletions
diff --git a/locale/en_GB.json b/locale/en_GB.json index c7cc90a..6cec70e 100644 --- a/locale/en_GB.json +++ b/locale/en_GB.json @@ -90,6 +90,14 @@ "preferences.requestToFollow.description": "Lets you approve other users before they are able to follow you", "preferences.smallIndicators.name": "Reduced unread indicators", "preferences.smallIndicators.description": "Hides the number of unread items and just shows a small dot instead", + "changePassword.heading": "Change password", + "changePassword.currentPassword": "Current password", + "changePassword.newPassword": "New password", + "changePassword.newPassword.repeat": "Confirm new password", + "changePassword.action": "Change", + "changePassword.error.currentIncorrect": "Current password is incorrect", + "changePassword.error.doesntMatch": "New password doesn't match", + "changePassword.success": "Password changed succesfully!", "globalSettings.pageTitle.instance": "Instance settings", "globalSettings.pageTitle.about": "About this instance", "globalSettings.categories": "Categories: ", 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 diff --git a/templates/change_password_form.php b/templates/change_password_form.php new file mode 100644 index 0000000..7a463fd --- /dev/null +++ b/templates/change_password_form.php @@ -0,0 +1,24 @@ +<form method="post" action="/todo" hx-post="/fragment/changePassword" hx-disabled-elt="find button" hx-swap="outerHTML"> + <div class="row"> + <label for="changePassword-current"><?= __('changePassword.currentPassword') ?></label> + <input type="password" id="changePassword-current" name="current" autocomplete="off" required + value="<?= $current ?? '' ?>"> + </div> + <div class="row"> + <label for="changePassword-new"><?= __('changePassword.newPassword') ?></label> + <input type="password" id="changePassword-new" name="new" autocomplete="off" required value="<?= $new ?? '' ?>"> + </div> + <div class="row"> + <label for="changePassword-newRepeat"><?= __('changePassword.newPassword.repeat') ?></label> + <input type="password" id="changePassword-newRepeat" name="newRepeat" autocomplete="off" required + value="<?= $newRepeat ?? '' ?>"> + </div> + <div class="row"> + <button class="primary"><?= __('changePassword.action') ?></button> + </div> + <?php if (isset($error)): ?> + <p class="error"><?= htmlspecialchars($error) ?></p> + <?php elseif ($success ?? false): ?> + <span class="temporaryIndicator"><?= __('changePassword.success') ?></span> + <?php endif; ?> +</form>
\ No newline at end of file diff --git a/templates/preferences_page.php b/templates/preferences_page.php index bcb39b6..2744747 100644 --- a/templates/preferences_page.php +++ b/templates/preferences_page.php @@ -1,4 +1,7 @@ <?php call_template('skeleton', ['pageTitle' => __('preferences.pageTitle')], function () { global $user, $saved; call_template('preferences_form', ['user' => $user, 'saved' => $saved ?? false]); + ?> + <h2><?= __('changePassword.heading') ?></h2> + <?php call_template('change_password_form'); });
\ No newline at end of file |
