Merge branch 'video_gstreamer-only'
[mediagoblin.git] / mediagoblin / auth / forms.py
CommitLineData
8e1e744d 1# GNU MediaGoblin -- federated, autonomous media hosting
12a100e4 2# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
24181820
CAW
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import wtforms
25ba955e 18import re
24181820 19
ae3bc7fa 20from mediagoblin.tools.translate import fake_ugettext_passthrough as _
4b1adc13 21
24181820
CAW
22
23class RegistrationForm(wtforms.Form):
24 username = wtforms.TextField(
4b1adc13 25 _('Username'),
24181820
CAW
26 [wtforms.validators.Required(),
27 wtforms.validators.Length(min=3, max=30),
6be33a77 28 wtforms.validators.Regexp(r'^\w+$')])
f5def6fe 29 password = wtforms.PasswordField(
4b1adc13 30 _('Password'),
24181820 31 [wtforms.validators.Required(),
f5def6fe 32 wtforms.validators.Length(min=6, max=30),
b8fbd817
CAW
33 wtforms.validators.EqualTo(
34 'confirm_password',
6be33a77 35 _('Passwords must match.'))])
f5def6fe 36 confirm_password = wtforms.PasswordField(
4b1adc13 37 _('Confirm password'),
04a7b06d
CAW
38 [wtforms.validators.Required()],
39 description=_(
40 u"Type it again here to make sure there are no spelling mistakes."))
24181820 41 email = wtforms.TextField(
4b1adc13 42 _('Email address'),
24181820 43 [wtforms.validators.Required(),
6be33a77 44 wtforms.validators.Email()])
a3776717
CAW
45
46
47class LoginForm(wtforms.Form):
48 username = wtforms.TextField(
4b1adc13 49 _('Username'),
a3776717
CAW
50 [wtforms.validators.Required(),
51 wtforms.validators.Regexp(r'^\w+$')])
52 password = wtforms.PasswordField(
4b1adc13 53 _('Password'),
a3776717 54 [wtforms.validators.Required()])
25ba955e
AV
55
56
57class ForgotPassForm(wtforms.Form):
58 username = wtforms.TextField(
59 'Username or email',
60 [wtforms.validators.Required()])
61
243c3843
NY
62 def validate_username(form, field):
63 if not (re.match(r'^\w+$', field.data) or
64 re.match(r'^.+@[^.].*\.[a-z]{2,10}$', field.data,
65 re.IGNORECASE)):
25ba955e
AV
66 raise wtforms.ValidationError(u'Incorrect input')
67
68
69class ChangePassForm(wtforms.Form):
70 password = wtforms.PasswordField(
71 'Password',
72 [wtforms.validators.Required(),
73 wtforms.validators.Length(min=6, max=30),
74 wtforms.validators.EqualTo(
75 'confirm_password',
76 'Passwords must match.')])
77 confirm_password = wtforms.PasswordField(
78 'Confirm password',
79 [wtforms.validators.Required()])
80 userid = wtforms.HiddenField(
81 '',
82 [wtforms.validators.Required()])
83 token = wtforms.HiddenField(
84 '',
85 [wtforms.validators.Required()])