author | nishanth |
Fri, 09 Apr 2010 11:46:35 +0530 | |
changeset 3 | 182f216da4a8 |
parent 2 | c11afa8623f7 |
child 4 | ededea9ad08b |
permissions | -rw-r--r-- |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
1 |
from django.shortcuts import render_to_response, redirect |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
2 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
3 |
from django.contrib.auth import authenticate, login, logout |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
4 |
from django.contrib.auth.decorators import login_required |
2 | 5 |
|
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
6 |
from workshop.reg import forms as reg_forms |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
7 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
8 |
def login(request): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
9 |
""" get the user object from e-mail and then check for password. |
2 | 10 |
""" |
11 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
12 |
user = request.user |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
13 |
if user.is_authenticated(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
14 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
15 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
16 |
if request.method == "POST": |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
17 |
form = reg_forms.LoginForm(request.POST) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
18 |
if form.is_valid(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
19 |
email = form.cleaned_data['email'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
20 |
password = form.cleaned_data['password'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
21 |
username = User.objects.get(email__iexact=email) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
22 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
23 |
user = authenticate(username, password) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
24 |
login(request, user) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
25 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
26 |
else: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
27 |
return render_to_response('login.html', {'form':form}) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
28 |
else: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
29 |
form = LoginForm() |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
30 |
return render_to_response('login.html', {'form':form}) |