--- a/reg/forms.py Fri Apr 09 11:46:35 2010 +0530
+++ b/reg/forms.py Fri Apr 09 12:28:58 2010 +0530
@@ -3,33 +3,26 @@
from django.contrib.auth import authenticate
-class LoginForm(forms.ModelForm):
+class LoginForm(forms.Form):
""" a form to handle login.
"""
- class Meta:
- model = User
- fields = ['email', 'password']
+ email = forms.EmailField()
+ password = forms.CharField(widget=forms.PasswordInput)
def clean_email(self):
""" see if a user exists for this email.
"""
email = self.cleaned_data['email']
+ password = self.data['password']
try:
- self.user = User.objects.get(email__iexact=email)
- return email
+ username = User.objects.get(email__iexact=email).username
except User.DoesNotExist:
raise forms.ValidationError("Incorrect e-mail or password")
- def clean_password(self):
- """ now we know that the user exists.
- we see if he typed the password correctly.
- """
-
- password = self.cleaned_data['password']
- user = authenticate(self.user.username, password)
+ user = authenticate(username=username, password=password)
if not user:
raise forms.ValidationError("Incorrect e-mail or password")
- return password
+ return email