author | Santosh G. Vattam <vattam.santosh@gmail.com> |
Mon, 10 Aug 2009 16:58:36 +0530 | |
changeset 36 | a7c525ec281a |
parent 18 | 05b9e60e6a10 |
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) |
|
18
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
36 |
if user.is_staff: |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
37 |
return HttpResponseRedirect('/proposal/review/') |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
38 |
else: |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
39 |
return HttpResponseRedirect('/proposal/submit/') |
1 | 40 |
else: |
41 |
pass |
|
42 |
# Return a 'disabled account' error message |
|
0 | 43 |
else: |
1 | 44 |
# Return an 'invalid login' error message. |
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
45 |
context['error'] = True |
1 | 46 |
|
47 |
return render_to_response(template, context) |
|
48 |
||
49 |
def create_account(request): |
|
50 |
"""Create an account for a user. |
|
51 |
""" |
|
52 |
||
53 |
if request.POST: |
|
54 |
username = request.POST['username'] |
|
55 |
password = request.POST['password'] |
|
56 |
confirm_pasword = request.POST['confirmpassword'] |
|
57 |
if password == confirm_pasword: |
|
58 |
try: |
|
59 |
user = User.objects.create_user(username, username, password) |
|
60 |
user.save() |
|
17 | 61 |
subject = "[Sakshath] Registration at Saskshath portal" |
62 |
message = """Hi, |
|
18
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
63 |
We have received a request for registration of your email address, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
64 |
"%s", to the http://sakshath.ac.in portal. |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
65 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
66 |
Your login credentials are: |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
67 |
username: %s |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
68 |
password: %s |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
69 |
|
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
70 |
-- |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
71 |
Regards, |
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
72 |
Saksath admin""" % (username, username, password) |
17 | 73 |
|
74 |
user.email_user(subject=subject, message=message) |
|
18
05b9e60e6a10
Changed CSS and removed Withdraw proposal.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
17
diff
changeset
|
75 |
|
1 | 76 |
context = { |
77 |
'created': True, |
|
78 |
'username': username, |
|
79 |
} |
|
80 |
except IntegrityError: |
|
81 |
context = { |
|
82 |
'exits': True, |
|
83 |
} |
|
84 |
else: |
|
85 |
context = { |
|
86 |
'password_err': True, |
|
87 |
} |
|
88 |
else: |
|
89 |
context = {} |
|
90 |
||
91 |
template = 'projrev/auth/create_account.html' |
|
92 |
||
93 |
return render_to_response(template, context) |
|
94 |
||
95 |
def forgot_password(request): |
|
96 |
"""Resend the password if forgotten. |
|
97 |
""" |
|
98 |
||
9 | 99 |
template = 'projrev/auth/forgot_password.html' |
1 | 100 |
if request.POST: |
9 | 101 |
context = { |
102 |
'password_sent': True, |
|
103 |
} |
|
1 | 104 |
else: |
105 |
context = {} |
|
9 | 106 |
|
1 | 107 |
|
108 |
return render_to_response(template, context) |
|
0 | 109 |
|
110 |
def logout_view(request): |
|
111 |
"""Logout the user |
|
112 |
""" |
|
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
113 |
|
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
114 |
logout(request) |
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
115 |
return HttpResponseRedirect(reverse('app.projrev.views.base.home')) |