author | Madhusudan.C.S <madhusudancs@gmail.com> |
Thu, 06 Aug 2009 20:20:36 +0530 | |
changeset 8 | 294ff7ac9cb6 |
parent 1 | 324233b04d76 |
child 9 | 38727da8a948 |
permissions | -rw-r--r-- |
0 | 1 |
"""This module contains the views for the login for the portal. |
2 |
""" |
|
3 |
||
4 |
||
5 |
__authors__ = [ |
|
6 |
'"Madhusudan.C.S" <madhusudancs@gmail.com>', |
|
7 |
] |
|
8 |
||
9 |
||
1 | 10 |
from django.contrib.auth import authenticate |
11 |
from django.contrib.auth import login |
|
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
12 |
from django.contrib.auth import logout |
1 | 13 |
from django.contrib.auth.forms import AuthenticationForm |
14 |
from django.contrib.auth.models import User |
|
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
15 |
from django.core.urlresolvers import reverse |
1 | 16 |
from django.db import IntegrityError |
17 |
from django.http import HttpResponseRedirect |
|
18 |
from django.shortcuts import render_to_response |
|
19 |
from django.shortcuts import get_object_or_404 |
|
0 | 20 |
|
21 |
||
22 |
def login_validate(request): |
|
23 |
"""Validate the user and log him in. |
|
24 |
""" |
|
25 |
||
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
26 |
template = 'projrev/auth/login.html' |
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
27 |
context = {} |
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
28 |
|
1 | 29 |
if request.POST: |
30 |
username = request.POST['username'] |
|
31 |
password = request.POST['password'] |
|
32 |
user = authenticate(username=username, password=password) |
|
33 |
if user is not None: |
|
34 |
if user.is_active: |
|
35 |
login(request, user) |
|
36 |
return HttpResponseRedirect('/proposal/submit/') |
|
37 |
else: |
|
38 |
pass |
|
39 |
# Return a 'disabled account' error message |
|
0 | 40 |
else: |
1 | 41 |
# Return an 'invalid login' error message. |
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
42 |
context['error'] = True |
1 | 43 |
|
44 |
return render_to_response(template, context) |
|
45 |
||
46 |
def create_account(request): |
|
47 |
"""Create an account for a user. |
|
48 |
""" |
|
49 |
||
50 |
if request.POST: |
|
51 |
username = request.POST['username'] |
|
52 |
password = request.POST['password'] |
|
53 |
confirm_pasword = request.POST['confirmpassword'] |
|
54 |
if password == confirm_pasword: |
|
55 |
try: |
|
56 |
user = User.objects.create_user(username, username, password) |
|
57 |
user.save() |
|
58 |
context = { |
|
59 |
'created': True, |
|
60 |
'username': username, |
|
61 |
} |
|
62 |
except IntegrityError: |
|
63 |
context = { |
|
64 |
'exits': True, |
|
65 |
} |
|
66 |
else: |
|
67 |
context = { |
|
68 |
'password_err': True, |
|
69 |
} |
|
70 |
else: |
|
71 |
context = {} |
|
72 |
||
73 |
template = 'projrev/auth/create_account.html' |
|
74 |
||
75 |
return render_to_response(template, context) |
|
76 |
||
77 |
def forgot_password(request): |
|
78 |
"""Resend the password if forgotten. |
|
79 |
""" |
|
80 |
||
81 |
if request.POST: |
|
0 | 82 |
pass |
1 | 83 |
else: |
84 |
context = {} |
|
85 |
template = 'projrev/auth/forgot_password.html' |
|
86 |
||
87 |
return render_to_response(template, context) |
|
0 | 88 |
|
89 |
def logout_view(request): |
|
90 |
"""Logout the user |
|
91 |
""" |
|
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
92 |
|
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
93 |
logout(request) |
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
94 |
return HttpResponseRedirect(reverse('app.projrev.views.base.home')) |