from django.contrib.auth.decorators import login_required from apps.changepw.models import ChangePasswordForm from django import forms from django.shortcuts import render_to_response from django.template import RequestContext from django.http import HttpResponseRedirect import subprocess @login_required(login_url='/nordunet/accounts/login/') 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'] # Magic for actually changing the password happens here 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)) else: form = ChangePasswordForm() return render_to_response('changepw/change_password.html', {'form': form, 'user': request.user}, context_instance=RequestContext(request))