CCrypto VPN public website https://vpn.ccrypto.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
2.0 KiB

  1. from django import forms
  2. from django.contrib.auth.models import User
  3. from django.utils.translation import ugettext_lazy as _
  4. from django.utils.safestring import mark_safe
  5. class FormPureRender:
  6. def as_pure_aligned(self):
  7. html = ''
  8. for f in self:
  9. html += '<div class="pure-control-group">\n'
  10. html += str(f.label_tag()) + '\n'
  11. html += str(f) + '\n'
  12. if f.errors:
  13. html += str(f.errors) + '\n'
  14. html += '</div>\n'
  15. return mark_safe(html)
  16. class UserField(forms.RegexField):
  17. def clean(self, value):
  18. super(UserField, self).clean(value)
  19. try:
  20. User.objects.get(username=value)
  21. raise forms.ValidationError(_("Username taken."))
  22. except User.DoesNotExist:
  23. return value
  24. class SignupForm(forms.Form, FormPureRender):
  25. username = UserField(
  26. label=_("Username"), min_length=2, max_length=16, regex='^[a-zA-Z0-9_-]+$',
  27. widget=forms.TextInput(attrs={'required': 'true',
  28. 'pattern': '[a-zA-Z0-9_-]{2,32}',
  29. 'placeholder': _("Username"),
  30. 'autofocus': 'true'})
  31. )
  32. password = forms.CharField(
  33. label=_("Password"),
  34. widget=forms.PasswordInput(attrs={'placeholder': _("Anything")})
  35. )
  36. password2 = forms.CharField(
  37. label=_("Repeat"),
  38. widget=forms.PasswordInput(attrs={'placeholder': _("Same Anything")})
  39. )
  40. email = forms.EmailField(
  41. label=_("E-Mail"),
  42. widget=forms.EmailInput(attrs={'placeholder': _("E-Mail")}),
  43. required=False,
  44. )
  45. def clean_password(self):
  46. if self.data['password'] != self.data['password2']:
  47. raise forms.ValidationError(_("Passwords are not the same"))
  48. return self.data['password']
  49. class ReqEmailForm(forms.Form, FormPureRender):
  50. email = forms.EmailField(
  51. label=_("E-Mail"),
  52. widget=forms.EmailInput(attrs={'placeholder': _("E-Mail")}),
  53. )