diff options
author | Johan Lundberg <lundberg@nordu.net> | 2011-01-27 14:37:56 +0100 |
---|---|---|
committer | Johan Lundberg <lundberg@nordu.net> | 2011-01-27 14:37:56 +0100 |
commit | f5b076151f4f7021a3842b41ba374c8dd65f6c85 (patch) | |
tree | ba690f93340e45487669f42703037c362a5786ce | |
parent | fa004e5941884c521d3b1a0ccfb681ccd5b06eb5 (diff) |
Added user authentication.
-rw-r--r-- | templates/changepw/change_password.html | 3 | ||||
-rw-r--r-- | 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 @@ </p> <form action="/changepw/" method="post" autocomplete="off">{% csrf_token %} <table> + <tr> + <th class="formlabel">Username:</th><td>{{ user.username }}</td> + </tr> {% for field in form %} <tr> <td class="fielderrors">{{ field.errors }}</td> @@ -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)) |