1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008 Lincoln de Sousa <lincoln@minaslivre.org>
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public
15 # License along with this program; if not, write to the
16 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 from django import forms
19 from django.forms import PasswordInput, ValidationError
20 from django.contrib.auth.models import User
23 class RegisterSpeaker(forms.Form):
24 username = forms.CharField(max_length=20, label=u'Usuário para login')
25 password1 = forms.CharField(widget=PasswordInput, label='Senha')
26 password2 = forms.CharField(widget=PasswordInput, label='Confirmar Senha')
28 def clean_password2(self):
29 if self.cleaned_data['password1'] != self.cleaned_data['password2']:
30 raise ValidationError('A confirmação não confere com a senha')
31 return self.cleaned_data['password2']
33 def clean_username(self):
35 User.objects.get(username=self.cleaned_data['username'])
36 raise ValidationError('Já existe um usuário com esse nome')
37 except User.DoesNotExist:
38 return self.cleaned_data['username']