X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/2f9cb34a07fcd98effda2fa900e48c31813f14c8..5ae7908036c081c642aafd1c37dfaf9b94bf2445:/redakcja/forms.py diff --git a/redakcja/forms.py b/redakcja/forms.py index 22f3bab6..0d21bb3a 100644 --- a/redakcja/forms.py +++ b/redakcja/forms.py @@ -1,7 +1,24 @@ +# -*- coding: utf-8 -*- +# +# This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from django import forms +from django.utils.translation import ugettext as _ +from django.contrib.auth.models import User + class RegistrationForm(forms.Form): first_name = forms.CharField() 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(): + raise forms.ValidationError(_('User with this email address already exists.')) + if len(email) > max_length: + raise forms.ValidationError(_('Username too long. Max length: %s') % max_length) + return email