1
|
|
|
""" |
2
|
|
|
byceps.blueprints.user.creation.forms |
3
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4
|
|
|
|
5
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
6
|
|
|
:License: Modified BSD, see LICENSE for details. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from uuid import UUID |
10
|
|
|
|
11
|
|
|
from wtforms import BooleanField, HiddenField, PasswordField, StringField |
12
|
|
|
from wtforms.validators import InputRequired, Length, ValidationError |
13
|
|
|
|
14
|
|
|
from ....services.user import screen_name_validator |
15
|
|
|
from ....util.l10n import LocalizedForm |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class ScreenNameValidator: |
19
|
|
|
"""Make sure screen name contains only permitted characters. |
20
|
|
|
|
21
|
|
|
However, do *not* check the length; use WTForms' `Length` for that. |
22
|
|
|
""" |
23
|
|
|
|
24
|
|
|
def __call__(self, form, field): |
25
|
|
|
if not screen_name_validator.contains_only_valid_chars(field.data): |
26
|
|
|
special_chars_spaced = ' '.join(screen_name_validator.SPECIAL_CHARS) |
27
|
|
|
raise ValidationError( |
28
|
|
|
'Enthält ungültige Zeichen. Erlaubt sind Buchstaben, ' |
29
|
|
|
f' Ziffern und diese Sonderzeichen: {special_chars_spaced}' |
30
|
|
|
) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class UserCreateForm(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=8)]) |
44
|
|
|
terms_version_id = HiddenField('AGB-Version', [InputRequired()]) |
45
|
|
|
consent_to_terms = BooleanField('AGB', [InputRequired()]) |
46
|
|
|
consent_to_privacy_policy = BooleanField('Datenschutzbestimmungen', [InputRequired()]) |
47
|
|
|
subscribe_to_newsletter = BooleanField('Newsletter') |
48
|
|
|
is_bot = BooleanField('Bot') |
49
|
|
|
|
50
|
|
|
@staticmethod |
51
|
|
|
def validate_terms_version_id(form, field): |
52
|
|
|
try: |
53
|
|
|
UUID(field.data) |
54
|
|
|
except ValueError: |
55
|
|
|
raise ValueError('Ungültige AGB-Version.') |
56
|
|
|
|
57
|
|
|
@staticmethod |
58
|
|
|
def validate_is_bot(form, field): |
59
|
|
|
if field.data: |
60
|
|
|
raise ValueError('Bots sind nicht erlaubt.') |
61
|
|
|
|