author | nishanth |
Fri, 09 Apr 2010 12:28:58 +0530 | |
changeset 4 | ededea9ad08b |
parent 3 | 182f216da4a8 |
child 6 | 057498d12450 |
permissions | -rw-r--r-- |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
1 |
from django.contrib.auth.models import User |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
2 |
from django import forms |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
3 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
4 |
from django.contrib.auth import authenticate |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
5 |
|
4 | 6 |
class LoginForm(forms.Form): |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
7 |
""" a form to handle login. |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
8 |
""" |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
9 |
|
4 | 10 |
email = forms.EmailField() |
11 |
password = forms.CharField(widget=forms.PasswordInput) |
|
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
12 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
13 |
def clean_email(self): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
14 |
""" see if a user exists for this email. |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
15 |
""" |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
16 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
17 |
email = self.cleaned_data['email'] |
4 | 18 |
password = self.data['password'] |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
19 |
try: |
4 | 20 |
username = User.objects.get(email__iexact=email).username |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
21 |
except User.DoesNotExist: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
22 |
raise forms.ValidationError("Incorrect e-mail or password") |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
23 |
|
4 | 24 |
user = authenticate(username=username, password=password) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
25 |
if not user: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
26 |
raise forms.ValidationError("Incorrect e-mail or password") |
4 | 27 |
return email |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
diff
changeset
|
28 |