forms.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import hashlib
  2. from django import forms
  3. from django.core.exceptions import ValidationError
  4. from django.utils.translation import ugettext_lazy as _
  5. from misago.forms import Form, QACaptchaField, ReCaptchaField
  6. from misago.models import User
  7. class UserResetPasswordForm(Form):
  8. email = forms.EmailField(max_length=255)
  9. captcha_qa = QACaptchaField()
  10. recaptcha = ReCaptchaField()
  11. error_source = 'email'
  12. layout = [
  13. (
  14. None,
  15. [('email', {'label': _("Your E-mail Address"), 'help_text': _("Enter email address password reset confirmation e-mail will be sent to. It must be valid e-mail you used to register on forums."), 'attrs': {'placeholder': _("Enter your e-mail address.")}})]
  16. ),
  17. (
  18. None,
  19. ['captcha_qa', 'recaptcha']
  20. ),
  21. ]
  22. def clean_email(self):
  23. try:
  24. email = self.cleaned_data['email'].lower()
  25. email_hash = hashlib.md5(email).hexdigest()
  26. self.found_user = User.objects.get(email_hash=email_hash)
  27. except User.DoesNotExist:
  28. raise ValidationError(_("There is no user with such e-mail address."))
  29. return email