# HG changeset patch # User nishanth # Date 1275905742 -19800 # Node ID b0e630caa6e677e161e41d13782ab0d38ff18e1d # Parent b9690fbf78afe06ce51cca65030b5b4089bcb8cd added required forms for login and logout diff -r b9690fbf78af -r b0e630caa6e6 sdi/forms.py --- a/sdi/forms.py Mon Jun 07 15:39:33 2010 +0530 +++ b/sdi/forms.py Mon Jun 07 15:45:42 2010 +0530 @@ -1,4 +1,5 @@ from django import forms +from django.contrib.auth import authenticate from sage_days.sdi.models import Registrant, TOPICS_CHOICES from captcha.fields import CaptchaField @@ -147,3 +148,21 @@ to_emails = [csv_list.split(',') for csv_list in emails.split()] return to_emails +class LoginForm(forms.form): + """ login form. + """ + + username = forms.CharField() + password = forms.CharField(widget=forms.PasswordInput) + + def clean_username(self): + username = self.cleaned_data['username'] + password = self.clean_password() + + if not authenticate(username=username, password=password): + raise forms.ValidationError("Invalid username or password") + + return username + + def clean_password(self): + return self.cleaned_data['password']