author | Madhusudan.C.S <madhusudancs@gmail.com> |
Fri, 07 Aug 2009 04:13:53 +0530 | |
changeset 17 | 5c1e26fa0fc4 |
parent 9 | 38727da8a948 |
child 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) |
|
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() |
|
17 | 58 |
subject = "[Sakshath] Registration at Saskshath portal" |
59 |
message = """Hi, |
|
60 |
We have received a request for registration of your |
|
61 |
email address, "%s", to the http://sakshath.ac.in mailing list. |
|
62 |
\n\n |
|
63 |
Your login credentials are:\n |
|
64 |
username: %s\n |
|
65 |
password: %s\n\n\n |
|
66 |
Regards, |
|
67 |
Saksath admin |
|
68 |
""" % (username, username, password) |
|
69 |
||
70 |
user.email_user(subject=subject, message=message) |
|
1 | 71 |
context = { |
72 |
'created': True, |
|
73 |
'username': username, |
|
74 |
} |
|
75 |
except IntegrityError: |
|
76 |
context = { |
|
77 |
'exits': True, |
|
78 |
} |
|
79 |
else: |
|
80 |
context = { |
|
81 |
'password_err': True, |
|
82 |
} |
|
83 |
else: |
|
84 |
context = {} |
|
85 |
||
86 |
template = 'projrev/auth/create_account.html' |
|
87 |
||
88 |
return render_to_response(template, context) |
|
89 |
||
90 |
def forgot_password(request): |
|
91 |
"""Resend the password if forgotten. |
|
92 |
""" |
|
93 |
||
9 | 94 |
template = 'projrev/auth/forgot_password.html' |
1 | 95 |
if request.POST: |
9 | 96 |
context = { |
97 |
'password_sent': True, |
|
98 |
} |
|
1 | 99 |
else: |
100 |
context = {} |
|
9 | 101 |
|
1 | 102 |
|
103 |
return render_to_response(template, context) |
|
0 | 104 |
|
105 |
def logout_view(request): |
|
106 |
"""Logout the user |
|
107 |
""" |
|
8
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
108 |
|
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
109 |
logout(request) |
294ff7ac9cb6
Added new set of files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
1
diff
changeset
|
110 |
return HttpResponseRedirect(reverse('app.projrev.views.base.home')) |