Merge remote branch 'remotes/aaronw/bug444_fix_utils_py_redux'
[mediagoblin.git] / mediagoblin / auth / forms.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
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
17 import wtforms
18 import re
19
20 from mediagoblin.tools.translate import fake_ugettext_passthrough as _
21
22
23 class RegistrationForm(wtforms.Form):
24 username = wtforms.TextField(
25 _('Username'),
26 [wtforms.validators.Required(),
27 wtforms.validators.Length(min=3, max=30),
28 wtforms.validators.Regexp(r'^\w+$')])
29 password = wtforms.PasswordField(
30 _('Password'),
31 [wtforms.validators.Required(),
32 wtforms.validators.Length(min=6, max=30),
33 wtforms.validators.EqualTo(
34 'confirm_password',
35 _('Passwords must match.'))])
36 confirm_password = wtforms.PasswordField(
37 _('Confirm password'),
38 [wtforms.validators.Required()],
39 description=_(
40 u"Type it again here to make sure there are no spelling mistakes."))
41 email = wtforms.TextField(
42 _('Email address'),
43 [wtforms.validators.Required(),
44 wtforms.validators.Email()])
45
46
47 class LoginForm(wtforms.Form):
48 username = wtforms.TextField(
49 _('Username'),
50 [wtforms.validators.Required(),
51 wtforms.validators.Regexp(r'^\w+$')])
52 password = wtforms.PasswordField(
53 _('Password'),
54 [wtforms.validators.Required()])
55
56
57 class 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
68 class 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