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
|
|
12 |
from django.contrib.auth.forms import AuthenticationForm
|
|
13 |
from django.contrib.auth.models import User
|
|
14 |
from django.db import IntegrityError
|
|
15 |
from django.http import HttpResponseRedirect
|
|
16 |
from django.shortcuts import render_to_response
|
|
17 |
from django.shortcuts import get_object_or_404
|
0
|
18 |
|
|
19 |
|
|
20 |
def login_validate(request):
|
|
21 |
"""Validate the user and log him in.
|
|
22 |
"""
|
|
23 |
|
1
|
24 |
if request.POST:
|
|
25 |
username = request.POST['username']
|
|
26 |
password = request.POST['password']
|
|
27 |
user = authenticate(username=username, password=password)
|
|
28 |
if user is not None:
|
|
29 |
if user.is_active:
|
|
30 |
login(request, user)
|
|
31 |
return HttpResponseRedirect('/proposal/submit/')
|
|
32 |
else:
|
|
33 |
pass
|
|
34 |
# Return a 'disabled account' error message
|
0
|
35 |
else:
|
1
|
36 |
# Return an 'invalid login' error message.
|
0
|
37 |
pass
|
|
38 |
else:
|
1
|
39 |
context = {}
|
|
40 |
template = 'projrev/auth/login.html'
|
|
41 |
|
|
42 |
return render_to_response(template, context)
|
|
43 |
|
|
44 |
def create_account(request):
|
|
45 |
"""Create an account for a user.
|
|
46 |
"""
|
|
47 |
|
|
48 |
if request.POST:
|
|
49 |
username = request.POST['username']
|
|
50 |
password = request.POST['password']
|
|
51 |
confirm_pasword = request.POST['confirmpassword']
|
|
52 |
if password == confirm_pasword:
|
|
53 |
try:
|
|
54 |
user = User.objects.create_user(username, username, password)
|
|
55 |
user.save()
|
|
56 |
context = {
|
|
57 |
'created': True,
|
|
58 |
'username': username,
|
|
59 |
}
|
|
60 |
except IntegrityError:
|
|
61 |
context = {
|
|
62 |
'exits': True,
|
|
63 |
}
|
|
64 |
else:
|
|
65 |
context = {
|
|
66 |
'password_err': True,
|
|
67 |
}
|
|
68 |
else:
|
|
69 |
context = {}
|
|
70 |
|
|
71 |
template = 'projrev/auth/create_account.html'
|
|
72 |
|
|
73 |
return render_to_response(template, context)
|
|
74 |
|
|
75 |
def forgot_password(request):
|
|
76 |
"""Resend the password if forgotten.
|
|
77 |
"""
|
|
78 |
|
|
79 |
if request.POST:
|
0
|
80 |
pass
|
1
|
81 |
else:
|
|
82 |
context = {}
|
|
83 |
template = 'projrev/auth/forgot_password.html'
|
|
84 |
|
|
85 |
return render_to_response(template, context)
|
0
|
86 |
|
|
87 |
def logout_view(request):
|
|
88 |
"""Logout the user
|
|
89 |
"""
|
|
90 |
|