added required forms for login and logout anoop
authornishanth
Mon, 07 Jun 2010 15:45:42 +0530
branchanoop
changeset 68 b0e630caa6e6
parent 67 b9690fbf78af
child 69 5ae81766e3e5
added required forms for login and logout
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']