~fluix/tilde

ref: 8385d93a45d225db407548099e08a11cb983d995 tilde/auth/forms.py -rw-r--r-- 1.3 KiB
8385d93aSteven Guikal Update privacy policy and require acceptance of it for registration 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# SPDX-FileCopyrightText: 2021 Steven Guikal <void@fluix.one>
#
# SPDX-License-Identifier: AGPL-3.0-only

from flask import Markup, url_for
from wtforms import BooleanField, Form, PasswordField, StringField
from wtforms.validators import Email, EqualTo, InputRequired, Length, Regexp
from wtforms.widgets import TextArea


class LoginForm(Form):
    username = StringField("Username", [InputRequired()])
    password = PasswordField("Password", [InputRequired()])


class RegistrationForm(Form):
    username = StringField(
        "Username",
        [
            InputRequired(),
            Regexp("[a-zA-Z0-9]{2,20}", message="Input must be alphanumeric."),
            Length(min=2, max=20),
        ],
    )
    email = StringField("Email", [InputRequired(), Email()])
    password1 = PasswordField(
        "Password",
        [
            InputRequired(),
            Length(min=16),
            EqualTo("password2", message="Passwords must match."),
        ],
    )
    password2 = PasswordField("Password (confirm)", [InputRequired()])
    bio = StringField("Biography", [InputRequired()], widget=TextArea())
    tos = BooleanField(
        Markup(
            f'I have read the <a href="{url_for("flatpages.privacy")}">privacy policy</a> and agree to follow the <a href="{url_for("flatpages.coc")}">code of conduct</a>.'
        ),
        [InputRequired()],
    )