diff options
author | Rodney Ewing <ewing.rj@gmail.com> | 2013-05-20 14:04:02 -0700 |
---|---|---|
committer | Rodney Ewing <ewing.rj@gmail.com> | 2013-05-20 14:28:43 -0700 |
commit | 39aa1db4d69eb2fb49da463f973484b501b3ee52 (patch) | |
tree | c4a1df1943338ba6cbab41e8de8edfd2e00b8904 /mediagoblin/edit/views.py | |
parent | 4adc3a85dda878b40f44e07b2283d4c55c6c5d02 (diff) | |
download | mediagoblin-39aa1db4d69eb2fb49da463f973484b501b3ee52.tar.lz mediagoblin-39aa1db4d69eb2fb49da463f973484b501b3ee52.tar.xz mediagoblin-39aa1db4d69eb2fb49da463f973484b501b3ee52.zip |
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}) |