Login mechanism.
--- a/app/projrev/views/helpers/forms.py Tue Aug 04 02:21:15 2009 -0400
+++ b/app/projrev/views/helpers/forms.py Tue Aug 04 19:42:47 2009 +0530
@@ -40,4 +40,4 @@
# Create a form from Review data model.
model = Review
- exclude = ('reviewer')
\ No newline at end of file
+ exclude = ('reviewer')
--- a/app/projrev/views/login.py Tue Aug 04 02:21:15 2009 -0400
+++ b/app/projrev/views/login.py Tue Aug 04 19:42:47 2009 +0530
@@ -7,27 +7,82 @@
]
-from django.contrib.auth import authenticate, login
-from django.shortcuts import render_to_response, get_object_or_404
+from django.contrib.auth import authenticate
+from django.contrib.auth import login
+from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth.models import User
+from django.db import IntegrityError
+from django.http import HttpResponseRedirect
+from django.shortcuts import render_to_response
+from django.shortcuts import get_object_or_404
def login_validate(request):
"""Validate the user and log him in.
"""
- username = request.POST['username']
- password = request.POST['password']
- user = authenticate(username=username, password=password)
- if user is not None:
- if user.is_active:
- login(request, user)
- # Redirect to a success page.
+ if request.POST:
+ username = request.POST['username']
+ password = request.POST['password']
+ user = authenticate(username=username, password=password)
+ if user is not None:
+ if user.is_active:
+ login(request, user)
+ return HttpResponseRedirect('/proposal/submit/')
+ else:
+ pass
+ # Return a 'disabled account' error message
else:
+ # Return an 'invalid login' error message.
pass
- # Return a 'disabled account' error message
else:
- # Return an 'invalid login' error message.
+ context = {}
+ template = 'projrev/auth/login.html'
+
+ return render_to_response(template, context)
+
+def create_account(request):
+ """Create an account for a user.
+ """
+
+ if request.POST:
+ username = request.POST['username']
+ password = request.POST['password']
+ confirm_pasword = request.POST['confirmpassword']
+ if password == confirm_pasword:
+ try:
+ user = User.objects.create_user(username, username, password)
+ user.save()
+ context = {
+ 'created': True,
+ 'username': username,
+ }
+ except IntegrityError:
+ context = {
+ 'exits': True,
+ }
+ else:
+ context = {
+ 'password_err': True,
+ }
+ else:
+ context = {}
+
+ template = 'projrev/auth/create_account.html'
+
+ return render_to_response(template, context)
+
+def forgot_password(request):
+ """Resend the password if forgotten.
+ """
+
+ if request.POST:
pass
+ else:
+ context = {}
+ template = 'projrev/auth/forgot_password.html'
+
+ return render_to_response(template, context)
def logout_view(request):
"""Logout the user
--- a/app/templates/projrev/base.html Tue Aug 04 02:21:15 2009 -0400
+++ b/app/templates/projrev/base.html Tue Aug 04 19:42:47 2009 +0530
@@ -9,10 +9,15 @@
<meta name="Author" content="Madhusudan.C.S - madhusudancs@gmail.com" />
<meta name="Robots" content="index,follow" />
-{% block scripts %}
+{% block stylesheets %}
<link rel="stylesheet" href="/site-content/css/projrev.css" type="text/css"/>
+{% endblock stylesheets %}
+
+{% block scripts %}
+ <script type="text/javascript"
+ src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
+ </script>
{% endblock scripts %}
-
<title>National Mission on Education through ICT</title>
</head>
--- a/app/urls.py Tue Aug 04 02:21:15 2009 -0400
+++ b/app/urls.py Tue Aug 04 19:42:47 2009 +0530
@@ -17,6 +17,8 @@
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^login/$', 'app.projrev.views.login.login_validate'),
+ (r'^create_account/$', 'app.projrev.views.login.create_account'),
+ (r'^forgot_password/$', 'app.projrev.views.login.forgot_password'),
(r'^logout/$', 'app.projrev.views.login.logout_view'),
(r'^proposal/submit/$', 'app.projrev.views.proposal.submit'),
(r'^proposal/review/$', 'app.projrev.views.proposal.review'),