summaryrefslogtreecommitdiff
path: root/views.py
blob: 6060098da2554d0056f3f1b36d66701ac8effde2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django.contrib.auth.decorators import login_required
from 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
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))