mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
Previously no check was performed to ensure that the same email wasn't used to register twice. Here we add a validator to perform that check. We also noted that the domain field was omitted, but checked by a client of this class. Therefore, we add it directly. (imported from commit 1411bf0adeb3cd048278376b059a26a0da4c54df)
22 lines
709 B
Python
22 lines
709 B
Python
from django import forms
|
|
from django.core import validators
|
|
from django.core.exceptions import ValidationError
|
|
from django.contrib.auth.models import User
|
|
|
|
def is_unique(value):
|
|
try:
|
|
print "foo + " + value
|
|
User.objects.get(email=value)
|
|
raise ValidationError(u'%s is already registered' % value)
|
|
except User.DoesNotExist:
|
|
pass
|
|
|
|
class UniqueEmailField(forms.EmailField):
|
|
default_validators = [validators.validate_email, is_unique]
|
|
|
|
class RegistrationForm(forms.Form):
|
|
full_name = forms.CharField(max_length=100)
|
|
email = UniqueEmailField()
|
|
password = forms.CharField(widget=forms.PasswordInput, max_length=100)
|
|
domain = forms.CharField(max_length=100)
|