From f5b076151f4f7021a3842b41ba374c8dd65f6c85 Mon Sep 17 00:00:00 2001 From: Johan Lundberg Date: Thu, 27 Jan 2011 14:37:56 +0100 Subject: Added user authentication. --- templates/changepw/change_password.html | 3 +++ views.py | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/templates/changepw/change_password.html b/templates/changepw/change_password.html index b6731cc..b650b73 100644 --- a/templates/changepw/change_password.html +++ b/templates/changepw/change_password.html @@ -18,6 +18,9 @@

{% csrf_token %} + + + {% for field in form %} diff --git a/views.py b/views.py index d95859a..6060098 100644 --- a/views.py +++ b/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth.decorators import login_required from changepw.models import ChangePasswordForm from django import forms from django.shortcuts import render_to_response @@ -5,16 +6,22 @@ from django.template import RequestContext from django.http import HttpResponseRedirect import subprocess +@login_required def change_password(request): + ''' + If the user is authenticated and the form is valid the password + changing script will be run with the username and new password. + ''' if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): new_password = form.cleaned_data['new_password'] - # Get user name and additional info from headers - # Magic for actually changing the password happens here - return_value = subprocess.call(['echo', new_password]) + return_value = subprocess.call(['echo', + request.user.username, + new_password]) + return render_to_response('changepw/change_password.html', {'return_value': return_value}, context_instance=RequestContext(request)) @@ -22,5 +29,5 @@ def change_password(request): form = ChangePasswordForm() return render_to_response('changepw/change_password.html', - {'form': form }, + {'form': form, 'user': request.user}, context_instance=RequestContext(request)) -- cgit v1.1
Username:{{ user.username }}
{{ field.errors }}