Coverage for seedboxsync/front/forms/user.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-26 17:14 +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.""" 

8 

9from flask_wtf import FlaskForm 

10from wtforms import EmailField, PasswordField, StringField 

11from wtforms.validators import DataRequired, Length, Optional 

12from seedboxsync.front.babel import gettext as _ 

13 

14 

15class UserBaseForm(FlaskForm): # type: ignore[misc] 

16 """ 

17 Base form for managing core user account details. 

18 

19 Provides common input fields and data validation rules shared across 

20 user creation and edition workflows. 

21 """ 

22 

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 

26 

27class UserEditForm(UserBaseForm): 

28 """ 

29 Form for editing existing user account details. 

30 

31 Extends the base user form with an optional password field to allow 

32 updating user credentials without forcing a password reset. 

33 """ 

34 

35 password = PasswordField(_("Password"), validators=[Optional(), Length(min=8, max=128)], render_kw={"placeholder": "••••••••••••", "icon": "fa-lock"}) 

36 

37 

38class UserCreateForm(UserBaseForm): 

39 """ 

40 Form for creating new user accounts. 

41 

42 Extends the base user form with a mandatory password field to ensure 

43 a password is provided during initial account creation. 

44 """ 

45 

46 password = PasswordField(_("Password"), validators=[DataRequired(), Length(min=8, max=128)], render_kw={"placeholder": "••••••••••••", "icon": "fa-lock"})