forms.py 992 B

1234567891011121314151617181920212223
  1. import hashlib
  2. from django.core.exceptions import ValidationError
  3. from django.utils.translation import ugettext_lazy as _
  4. import floppyforms as forms
  5. from misago.forms import Form, QACaptchaField, ReCaptchaField
  6. from misago.models import User
  7. class UserSendActivationMailForm(Form):
  8. email = forms.EmailField(label=_("Your E-mail Address"),
  9. help_text=_("Enter email address send activation e-mail to. It must be valid e-mail you used to register on forums."),
  10. max_length=255)
  11. captcha_qa = QACaptchaField()
  12. recaptcha = ReCaptchaField()
  13. error_source = 'email'
  14. def clean_email(self):
  15. try:
  16. email = self.cleaned_data['email'].lower()
  17. email_hash = hashlib.md5(email).hexdigest()
  18. self.found_user = User.objects.get(email_hash=email_hash)
  19. except User.DoesNotExist:
  20. raise ValidationError(_("There is no user with such e-mail address."))
  21. return email