author | nishanth |
Fri, 09 Apr 2010 12:28:58 +0530 | |
changeset 4 | ededea9ad08b |
parent 3 | 182f216da4a8 |
child 5 | 37e4027fba48 |
permissions | -rw-r--r-- |
4 | 1 |
from django.contrib.auth.models import User |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
2 |
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
|
3 |
from django.contrib.auth.decorators import login_required |
2 | 4 |
|
4 | 5 |
from django.shortcuts import render_to_response, redirect |
6 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
7 |
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
|
8 |
|
4 | 9 |
from django.http import HttpResponse |
10 |
||
11 |
def homepage(request): |
|
12 |
""" see if the user is active. |
|
13 |
If not, only show the re send activation email link. |
|
14 |
else show all the options in homepage. |
|
15 |
""" |
|
16 |
||
17 |
user = request.user |
|
18 |
||
19 |
if not user.is_authenticated(): |
|
20 |
return HttpResponse('not logged in<br><a href="/reg/login">login</a>') |
|
21 |
elif not user.is_active: |
|
22 |
return HttpResponse('not active<br /><a href="/reg/logout">logout</a>') |
|
23 |
else: |
|
24 |
return HttpResponse('you are ogey<br /><a href="/reg/logout">logout</a>') |
|
25 |
||
26 |
def user_login(request): |
|
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
27 |
""" get the user object from e-mail and then check for password. |
2 | 28 |
""" |
29 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
30 |
user = request.user |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
31 |
if user.is_authenticated(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
32 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
33 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
34 |
if request.method == "POST": |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
35 |
form = reg_forms.LoginForm(request.POST) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
36 |
if form.is_valid(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
37 |
email = form.cleaned_data['email'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
38 |
password = form.cleaned_data['password'] |
4 | 39 |
username = User.objects.get(email__iexact=email).username |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
40 |
|
4 | 41 |
user = authenticate(username=username, password=password) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
42 |
login(request, user) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
43 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
44 |
else: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
45 |
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
|
46 |
else: |
4 | 47 |
form = reg_forms.LoginForm() |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
48 |
return render_to_response('login.html', {'form':form}) |
4 | 49 |
|
50 |
def user_logout(request): |
|
51 |
""" simply logout the user and redirect to homepage. |
|
52 |
""" |
|
53 |
||
54 |
logout(request) |
|
55 |
print "logged out" |
|
56 |
return redirect('/reg') |
|
57 |
||
58 |