forms.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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
  6. from misago import captcha
  7. from misago.users.models import User
  8. class UserSendActivationMailForm(Form):
  9. email = forms.EmailField(max_length=255)
  10. captcha_qa = captcha.QACaptchaField()
  11. recaptcha = captcha.ReCaptchaField()
  12. error_source = 'email'
  13. layout = [
  14. (
  15. None,
  16. [('email', {'label': _("Your E-mail Address"), 'help_text': _("Enter email address send activation e-mail to. It must be valid e-mail you used to register on forums."), 'attrs': {'placeholder': _("Enter your e-mail address.")}})]
  17. ),
  18. (
  19. None,
  20. ['captcha_qa', 'recaptcha']
  21. ),
  22. ]
  23. def clean_email(self):
  24. try:
  25. email = self.cleaned_data['email'].lower()
  26. email_hash = hashlib.md5(email).hexdigest()
  27. self.found_user = User.objects.get(email_hash=email_hash)
  28. except User.DoesNotExist:
  29. raise ValidationError(_("There is no user with such e-mail address."))
  30. return email