Merge remote branch 'remotes/elrond/misc/use_staticdirect'
[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
7960ac98 20from mediagoblin.util 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
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, re.IGNORECASE)):
65 raise wtforms.ValidationError(u'Incorrect input')
66
67
68class ChangePassForm(wtforms.Form):
69 password = wtforms.PasswordField(
70 'Password',
71 [wtforms.validators.Required(),
72 wtforms.validators.Length(min=6, max=30),
73 wtforms.validators.EqualTo(
74 'confirm_password',
75 'Passwords must match.')])
76 confirm_password = wtforms.PasswordField(
77 'Confirm password',
78 [wtforms.validators.Required()])
79 userid = wtforms.HiddenField(
80 '',
81 [wtforms.validators.Required()])
82 token = wtforms.HiddenField(
83 '',
84 [wtforms.validators.Required()])
85