forms.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # GNU MediaGoblin -- federated, autonomous media hosting
  2. # Copyright (C) 2011, 2012 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. import wtforms
  17. from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
  18. from mediagoblin.auth.tools import normalize_user_or_email_field
  19. class RegistrationForm(wtforms.Form):
  20. username = wtforms.StringField(
  21. _('Username'),
  22. [wtforms.validators.InputRequired(),
  23. normalize_user_or_email_field(allow_email=False)])
  24. password = wtforms.PasswordField(
  25. _('Password'),
  26. [wtforms.validators.InputRequired(),
  27. wtforms.validators.Length(min=5, max=1024)])
  28. email = wtforms.StringField(
  29. _('Email address'),
  30. [wtforms.validators.InputRequired(),
  31. normalize_user_or_email_field(allow_user=False)])
  32. class LoginForm(wtforms.Form):
  33. username = wtforms.StringField(
  34. _('Username or Email'),
  35. [wtforms.validators.InputRequired(),
  36. normalize_user_or_email_field()])
  37. password = wtforms.PasswordField(
  38. _('Password'))
  39. stay_logged_in = wtforms.BooleanField(
  40. label='',
  41. description=_('Stay logged in'))
  42. class ForgotPassForm(wtforms.Form):
  43. username = wtforms.StringField(
  44. _('Username or email'),
  45. [wtforms.validators.InputRequired(),
  46. normalize_user_or_email_field()])
  47. class ChangeForgotPassForm(wtforms.Form):
  48. password = wtforms.PasswordField(
  49. 'Password',
  50. [wtforms.validators.InputRequired(),
  51. wtforms.validators.Length(min=5, max=1024)])
  52. token = wtforms.HiddenField(
  53. '',
  54. [wtforms.validators.InputRequired()])
  55. class ChangePassForm(wtforms.Form):
  56. old_password = wtforms.PasswordField(
  57. _('Old password'),
  58. [wtforms.validators.InputRequired()],
  59. description=_(
  60. "Enter your old password to prove you own this account."))
  61. new_password = wtforms.PasswordField(
  62. _('New password'),
  63. [wtforms.validators.InputRequired(),
  64. wtforms.validators.Length(min=6, max=30)],
  65. id="password")