--- 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']