1 # -*- coding: utf-8 -*-
3 # This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django import forms
7 from django.core.urlresolvers import reverse
8 from django.utils.safestring import mark_safe
9 from django.utils.translation import ugettext as _
10 from django.contrib.auth.models import User
13 class RegistrationForm(forms.Form):
14 first_name = forms.CharField()
15 last_name = forms.CharField()
16 email = forms.EmailField()
17 password = forms.CharField(widget=forms.PasswordInput)
19 def clean_email(self):
20 max_length = User._meta.get_field('username').max_length
21 email = self.cleaned_data['email']
22 if User.objects.filter(username=email).exists():
24 'User with this email address already exists. '
25 '<a href="%s">Log in</a> or <a href="%s">reset your password</a>.') % (
26 reverse('login'), reverse('password_reset'))
27 raise forms.ValidationError(mark_safe(msg))
28 if len(email) > max_length:
29 raise forms.ValidationError(_('Username too long. Max length: %s') % max_length)