Coverage for seedboxsync/front/forms/user.py: 100%
12 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-31 17:10 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-31 17:10 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""SeedboxSync WTForms form for user management."""
9from flask_wtf import FlaskForm
10from wtforms import BooleanField, EmailField, PasswordField, StringField
11from wtforms.validators import DataRequired, Length, Optional
12from seedboxsync.front.babel import gettext as _
15class UserBaseForm(FlaskForm): # type: ignore[misc]
16 """
17 Base form for managing core user account details.
19 Provides common input fields and data validation rules shared across
20 user creation and edition workflows.
21 """
23 username = StringField(_("Username"), validators=[DataRequired(), Length(min=4, max=25)], render_kw={"placeholder": "admin", "icon": "fa-user"})
24 email = EmailField(_("Email"), validators=[DataRequired(), Length(min=8, max=35)], render_kw={"placeholder": "admin", "icon": "fa-user"})
25 is_admin = BooleanField(_("Is admin?"), default=False, render_kw={"icon": "fa-user-shield"})
28class UserEditForm(UserBaseForm):
29 """
30 Form for editing existing user account details.
32 Extends the base user form with an optional password field to allow
33 updating user credentials without forcing a password reset.
34 """
36 password = PasswordField(_("Password"), validators=[Optional(), Length(min=8, max=128)], render_kw={"placeholder": "••••••••••••", "icon": "fa-lock"})
39class UserCreateForm(UserBaseForm):
40 """
41 Form for creating new user accounts.
43 Extends the base user form with a mandatory password field to ensure
44 a password is provided during initial account creation.
45 """
47 password = PasswordField(_("Password"), validators=[DataRequired(), Length(min=8, max=128)], render_kw={"placeholder": "••••••••••••", "icon": "fa-lock"})