diff options
| author | Dennis Fink | 2026-11-17 21:23:57 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-17 21:23:57 +0100 |
| commit | acd1f42847786963fc4aaeed884c3091700c9e35 (patch) | |
| tree | 5a126bdfd96e69c985137bb2a3db8d9066ecd12d /webmentions_ssg/forms | |
| parent | c4c17e3e046a627a7d2353c734bc69f05d4fc3b1 (diff) | |
| download | webmentions-ssg-acd1f42847786963fc4aaeed884c3091700c9e35.tar.gz webmentions-ssg-acd1f42847786963fc4aaeed884c3091700c9e35.zip | |
feat(core): add user account page
Add an authenticated user page showing the current username and remote
address, including guidance for validating reverse-proxy hop
configuration.
Allow users to change their own password through a CSRF-protected
WTForms form while preserving the active session and invalidating other
existing sessions.
Diffstat (limited to 'webmentions_ssg/forms')
| -rw-r--r-- | webmentions_ssg/forms/user.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/webmentions_ssg/forms/user.py b/webmentions_ssg/forms/user.py index 3bb6421..ae1736d 100644 --- a/webmentions_ssg/forms/user.py +++ b/webmentions_ssg/forms/user.py @@ -2,11 +2,13 @@ # # SPDX-License-Identifier: BSD-3-Clause -"""User authentication forms.""" +"""User authentication and password-change forms.""" from flask_wtf import FlaskForm from wtforms import PasswordField, StringField, SubmitField -from wtforms.validators import InputRequired +from wtforms.validators import EqualTo, InputRequired, ValidationError + +from ..auth import validate_new_password class LoginForm(FlaskForm): @@ -15,3 +17,34 @@ class LoginForm(FlaskForm): username = StringField("Username", validators=[InputRequired()]) password = PasswordField("Password", validators=[InputRequired()]) submit = SubmitField("Sign In") + + +class ChangePasswordForm(FlaskForm): + """Verify the existing password and validate a replacement.""" + + current_password = PasswordField( + "Current password", + validators=[InputRequired()], + render_kw={"autocomplete": "current-password"}, + ) + new_password = PasswordField( + "New password", + validators=[InputRequired()], + render_kw={"autocomplete": "new-password"}, + ) + confirm_password = PasswordField( + "Confirm new password", + validators=[ + InputRequired(), + EqualTo("new_password", message="Passwords must match."), + ], + render_kw={"autocomplete": "new-password"}, + ) + submit = SubmitField("Change password") + + def validate_new_password(self, field: PasswordField) -> None: + """Apply the same password policy as the user-management CLI.""" + try: + validate_new_password(field.data or "") + except ValueError as exc: + raise ValidationError(str(exc)) from exc |
