diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2013-05-21 18:34:23 +0200 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2013-05-21 18:34:23 +0200 |
commit | d5e035e9193cb9c9faff0e8601e2908bf5285f9c (patch) | |
tree | 7cdc675b8b8e504f5f0087dd5b275fa596685406 /mediagoblin/edit/views.py | |
parent | 6c1467d570a4da68ef8b4edac9aecdb9c87a61de (diff) | |
parent | 2ba7603469a80ccfc1c07ddebc53ad6c6f0a6f79 (diff) | |
download | mediagoblin-d5e035e9193cb9c9faff0e8601e2908bf5285f9c.tar.lz mediagoblin-d5e035e9193cb9c9faff0e8601e2908bf5285f9c.tar.xz mediagoblin-d5e035e9193cb9c9faff0e8601e2908bf5285f9c.zip |
Merge remote-tracking branch 'rodney757/change_pass'
* rodney757/change_pass:
fixed translation, and changed tabs to spaces, and change it so the user can view their password as they're typing.
modified change_pass tests
moved change pass to a seperate view and fixed issues 709
Diffstat (limited to 'mediagoblin/edit/views.py')
-rw-r--r-- | mediagoblin/edit/views.py | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index bfcf65b5..508c380d 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -229,18 +229,6 @@ def edit_account(request): form.wants_comment_notification.data if form_validated and \ - form.new_password.data or form.old_password.data: - password_matches = auth_lib.bcrypt_check_password( - form.old_password.data, - user.pw_hash) - if password_matches: - #the entire form validates and the password matches - user.pw_hash = auth_lib.bcrypt_gen_password_hash( - form.new_password.data) - else: - form.old_password.errors.append(_('Wrong password')) - - if form_validated and \ form.license_preference.validate(form): user.license_preference = \ form.license_preference.data @@ -345,3 +333,39 @@ def edit_collection(request, collection): 'mediagoblin/edit/edit_collection.html', {'collection': collection, 'form': form}) + + +@require_active_login +def change_pass(request): + form = forms.ChangePassForm(request.form) + user = request.user + + if request.method == 'POST' and form.validate(): + + if not auth_lib.bcrypt_check_password( + form.old_password.data, user.pw_hash): + form.old_password.errors.append( + _('Wrong password')) + + return render_to_response( + request, + 'mediagoblin/edit/change_pass.html', + {'form': form, + 'user': user}) + + # Password matches + user.pw_hash = auth_lib.bcrypt_gen_password_hash( + form.new_password.data) + user.save() + + messages.add_message( + request, messages.SUCCESS, + _('Your password was changed successfully')) + + return redirect(request, 'mediagoblin.edit.account') + + return render_to_response( + request, + 'mediagoblin/edit/change_pass.html', + {'form': form, + 'user': user}) |