summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Lundberg <lundberg@nordu.net>2011-08-03 13:41:11 +0200
committerJohan Lundberg <lundberg@nordu.net>2011-08-03 13:41:11 +0200
commitd6bf5e609ce1f2a8efeb762bd073b0c0839f158c (patch)
treeac571a27563c372d9791b83ef027af95ebcc4369
parent3c6aa487eb14970e0b1f59859bb43d67e2aad65e (diff)
change_password and reset_password now takes a password type (pwtype) instead of a request.
-rw-r--r--urls.py4
-rw-r--r--views.py36
2 files changed, 18 insertions, 22 deletions
diff --git a/urls.py b/urls.py
index e4d2f1d..8d38e88 100644
--- a/urls.py
+++ b/urls.py
@@ -3,8 +3,8 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('apps.changepw.views',
url(r'^/$', 'index', name='index'),
- url(r'^/changepw$', 'change_password', name='changepw'),
- url(r'^/resetpw$', 'reset_password', name='resetpw'),
+ url(r'^/changepw/(?P<pwtype>[-\w]+)$', 'change_password', name='changepw'),
+ url(r'^/resetpw/(?P<pwtype>[-\w]+)$', 'reset_password', name='resetpw'),
url(r'^/changeother$', 'change_other', name='changeother'),
url(r'^/changeother/[-\w]+$', 'change_other'),
)
diff --git a/views.py b/views.py
index ba09989..45790aa 100644
--- a/views.py
+++ b/views.py
@@ -6,14 +6,14 @@ import re
import random
# import your_pw_change_module
-def _change_password(request, user, new_password):
+def _change_password(pwtype, user, new_password):
'''
Use this to call your change password function.
'''
# ret = your_pw_change_module.change_password(user, new_password)
return 0
-def _reset_password(request, user, new_password):
+def _reset_password(pwtype, user, new_password):
'''
Use this to call your reset password function.
'''
@@ -38,15 +38,6 @@ def _get_username(request):
request.user.username == username@domain.com
'''
return request.user.username.split('@')[0]
-
-#def _generate_password(n):
-# '''
-# Returns a psudo random string of lenght n.
-# http://code.activestate.com/recipes/576722-pseudo-random-string/
-# '''
-# import os, math
-# from base64 import b64encode
-# return b64encode(os.urandom(int(math.ceil(0.75*n))),'-_')[:n]
def _generate_password(n, z=3):
'''
@@ -96,7 +87,7 @@ def index(request):
context_instance=RequestContext(request))
@login_required(login_url='/sso/accounts/login/')
-def change_password(request):
+def change_password(request, pwtype):
'''
If the user is authenticated and the form is valid the password
changing script will be run with the username and new password.
@@ -108,16 +99,20 @@ def change_password(request):
form = ChangePasswordForm(request.POST)
if form.is_valid():
new_password = form.cleaned_data['new_password']
- return_value = _change_password(request, request.user, new_password)
- return render_to_response(tmpl, {'return_value': return_value},
- context_instance=RequestContext(request))
+ return_value = _change_password(pwtype, request.user, new_password)
+ return render_to_response(tmpl,
+ {'pwtype': pwtype,
+ 'return_value': return_value},
+ context_instance=RequestContext(request))
else:
form = ChangePasswordForm()
- return render_to_response(tmpl, {'form': form, 'username': username},
+ return render_to_response(tmpl,
+ {'form': form, 'username': username,
+ 'pwtype': pwtype},
context_instance=RequestContext(request))
@login_required(login_url='/sso/accounts/login/')
-def reset_password(request):
+def reset_password(request, pwtype):
'''
Resets password for the authenticated user to a random string.
The function that actually sets the new password has to be provided as func.
@@ -130,12 +125,13 @@ def reset_password(request):
return_value = _reset_password(request, request.user, new_password)
return render_to_response(tmpl,
{'username': username, 'new_password': new_password,
- 'return_value': return_value},
+ 'pwtype': pwtype, 'return_value': return_value},
context_instance=RequestContext(request))
else:
return render_to_response(tmpl,
- {'username': username, 'return_value': None},
- context_instance=RequestContext(request))
+ {'username': username, 'return_value': None,
+ 'pwtype': pwtype},
+ context_instance=RequestContext(request))
@login_required(login_url='/sso/accounts/login/')
def change_other(request, *args):