X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/31006b86a2e9883d8a4c5fe18128821b325773ab..039112897b09b05153d79ca9a2d9ed114827d294:/redakcja/forms.py diff --git a/redakcja/forms.py b/redakcja/forms.py index 16ad87e7..0a771c75 100644 --- a/redakcja/forms.py +++ b/redakcja/forms.py @@ -4,6 +4,10 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django import forms +from django.core.urlresolvers import reverse +from django.utils.safestring import mark_safe +from django.utils.translation import ugettext as _ +from django.contrib.auth.models import User class RegistrationForm(forms.Form): @@ -11,3 +15,16 @@ class RegistrationForm(forms.Form): last_name = forms.CharField() email = forms.EmailField() password = forms.CharField(widget=forms.PasswordInput) + + def clean_email(self): + max_length = User._meta.get_field('username').max_length + email = self.cleaned_data['email'] + if User.objects.filter(username=email).exists(): + msg = _( + 'User with this email address already exists. ' + 'Log in or reset your password.') % ( + reverse('login'), reverse('password_reset')) + raise forms.ValidationError(mark_safe(msg)) + if len(email) > max_length: + raise forms.ValidationError(_('Username too long. Max length: %s') % max_length) + return email