1
|
|
|
""" |
2
|
|
|
byceps.blueprints.admin.user.forms |
3
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4
|
|
|
|
5
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
6
|
|
|
:License: Modified BSD, see LICENSE for details. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from wtforms import PasswordField, SelectField, StringField, TextAreaField |
10
|
|
|
from wtforms.validators import InputRequired, Length, Optional, ValidationError |
11
|
|
|
|
12
|
|
|
from ....services.site import service as site_service |
13
|
|
|
from ....services.user import screen_name_validator |
14
|
|
|
from ....util.l10n import LocalizedForm |
15
|
|
|
|
16
|
|
|
from ...user.creation.forms import ScreenNameValidator |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
MINIMUM_PASSWORD_LENGTH = 10 |
20
|
|
|
MAXIMUM_PASSWORD_LENGTH = 100 |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class ChangeScreenNameForm(LocalizedForm): |
24
|
|
|
screen_name = StringField('Neuer Benutzername', [ |
25
|
|
|
InputRequired(), |
26
|
|
|
Length(min=screen_name_validator.MIN_LENGTH, |
27
|
|
|
max=screen_name_validator.MAX_LENGTH), |
28
|
|
|
ScreenNameValidator(), |
29
|
|
|
]) |
30
|
|
|
reason = TextAreaField('Begründung', validators=[InputRequired(), Length(max=400)]) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class CreateAccountForm(LocalizedForm): |
34
|
|
|
screen_name = StringField('Benutzername', [ |
35
|
|
|
InputRequired(), |
36
|
|
|
Length(min=screen_name_validator.MIN_LENGTH, |
37
|
|
|
max=screen_name_validator.MAX_LENGTH), |
38
|
|
|
ScreenNameValidator(), |
39
|
|
|
]) |
40
|
|
|
first_names = StringField('Vorname(n)', [InputRequired(), Length(min=2, max=40)]) |
41
|
|
|
last_name = StringField('Nachname', [InputRequired(), Length(min=2, max=40)]) |
42
|
|
|
email_address = StringField('E-Mail-Adresse', [InputRequired(), Length(min=6)]) |
43
|
|
|
password = PasswordField('Passwort', [InputRequired(), Length(min=MINIMUM_PASSWORD_LENGTH, max=MAXIMUM_PASSWORD_LENGTH)]) |
44
|
|
|
site_id = SelectField('Site-ID', validators=[Optional()]) |
45
|
|
|
|
46
|
|
|
def set_site_choices(self): |
47
|
|
|
sites = site_service.get_all_sites() |
48
|
|
|
sites.sort(key=lambda site: site.id) |
49
|
|
|
|
50
|
|
|
choices = [(str(site.id), site.id) for site in sites] |
51
|
|
|
choices.insert(0, ('', '<keine>')) |
52
|
|
|
self.site_id.choices = choices |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
class DeleteAccountForm(LocalizedForm): |
56
|
|
|
reason = TextAreaField('Begründung', validators=[InputRequired(), Length(max=400)]) |
57
|
|
|
verification = StringField('Bestätigung', validators=[InputRequired()]) |
58
|
|
|
|
59
|
|
|
def validate_verification(form, field): |
60
|
|
|
if field.data != 'löschen': |
61
|
|
|
raise ValidationError('Ungültiges Bestätigungswort') |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
class SetPasswordForm(LocalizedForm): |
65
|
|
|
password = PasswordField('Passwort', [InputRequired(), Length(min=MINIMUM_PASSWORD_LENGTH, max=MAXIMUM_PASSWORD_LENGTH)]) |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
class SuspendAccountForm(LocalizedForm): |
69
|
|
|
reason = TextAreaField('Begründung', validators=[InputRequired(), Length(max=400)]) |
70
|
|
|
|