aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/forms/__init__.py
blob: 5d2f8277bc1b90fa9ba7f7812d03e3c450571a64 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
#
# SPDX-License-Identifier: BSD-3-Clause

import re

from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField
from wtforms.validators import URL, InputRequired, Regexp

from .validators import AllowedHostname, NotEqualTo, PublicURL


class LoginForm(FlaskForm):
    """
    Form for authenticating a user.
    """

    username = StringField("Username", validators=[InputRequired()])
    password = PasswordField("Password", validators=[InputRequired()])
    submit = SubmitField("Sign In")


class EndpointForm(FlaskForm):
    """
    Form for receiving a Webmention.

    The source must be a public HTTP or HTTPS URL distinct from the target.
    The target must be an HTTP or HTTPS URL using an allowed hostname.
    """

    source = StringField(
        "source",
        validators=[
            InputRequired(),
            URL(),
            Regexp(
                "^https?://.*",
                flags=re.IGNORECASE,
                message="source must begin with http or https",
            ),
            NotEqualTo("target"),
            PublicURL(),
        ],
    )
    target = StringField(
        "target",
        validators=[
            InputRequired(),
            URL(),
            Regexp(
                "^https?://.*",
                flags=re.IGNORECASE,
                message="target must begin with http or https",
            ),
            AllowedHostname(),
        ],
    )


class AdminActionForm(FlaskForm):
    """
    Form for confirming an administrative action.
    """

    submit = SubmitField("Confirm")