Fix bad merge
[cascardo/ema.git] / eventos / forms.py
index 8e3980e..2a46963 100644 (file)
 # License along with this program; if not, write to the
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
+from django import forms
+from django.forms import PasswordInput, ValidationError
+from django.contrib.auth.models import User
+
+
+class RegisterSpeaker(forms.Form):
+    username = forms.CharField(max_length=20, label=u'Usuário para login')
+    password1 = forms.CharField(widget=PasswordInput, label='Senha')
+    password2 = forms.CharField(widget=PasswordInput, label='Confirmar Senha')
+
+    def clean_password2(self):
+        if self.cleaned_data['password1'] != self.cleaned_data['password2']:
+            raise ValidationError('A confirmação não confere com a senha')
+        return self.cleaned_data['password2']
+
+    def clean_username(self):
+        try:
+            User.objects.get(username=self.cleaned_data['username'])
+            raise ValidationError('Já existe um usuário com esse nome')
+        except User.DoesNotExist:
+            return self.cleaned_data['username']