From 93d805ad6b0e5324c515323d2fc0a4a7ea3f1dad Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Thu, 8 Aug 2013 15:07:07 -0700 Subject: add user prefrence for insite notifications --- mediagoblin/edit/forms.py | 2 ++ mediagoblin/edit/views.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'mediagoblin/edit') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 85c243a0..5de1bf96 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -67,6 +67,8 @@ class EditAccountForm(wtforms.Form): normalize_user_or_email_field(allow_user=False)]) wants_comment_notification = wtforms.BooleanField( description=_("Email me when others comment on my media")) + wants_notifications = wtforms.BooleanField( + description=_("Enable/Disable insite notifications")) license_preference = wtforms.SelectField( _('License preference'), [ diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 6aa2acd9..a11cb932 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -228,10 +228,12 @@ def edit_account(request): user = request.user form = forms.EditAccountForm(request.form, wants_comment_notification=user.wants_comment_notification, - license_preference=user.license_preference) + license_preference=user.license_preference, + wants_notifications=user.wants_notifications) if request.method == 'POST' and form.validate(): user.wants_comment_notification = form.wants_comment_notification.data + user.wants_notifications = form.wants_notifications.data user.license_preference = form.license_preference.data -- cgit v1.2.3 From 402f43601164e26390cf7c78a383537eb009e499 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Thu, 11 Jul 2013 16:16:41 -0700 Subject: maybe have change password and email on same page --- mediagoblin/edit/forms.py | 16 +++++++--- mediagoblin/edit/routing.py | 2 ++ mediagoblin/edit/views.py | 76 +++++++++++++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 31 deletions(-) (limited to 'mediagoblin/edit') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 85c243a0..71f30520 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -61,10 +61,6 @@ class EditProfileForm(wtforms.Form): class EditAccountForm(wtforms.Form): - new_email = wtforms.TextField( - _('New email address'), - [wtforms.validators.Optional(), - normalize_user_or_email_field(allow_user=False)]) wants_comment_notification = wtforms.BooleanField( description=_("Email me when others comment on my media")) license_preference = wtforms.SelectField( @@ -111,3 +107,15 @@ class ChangePassForm(wtforms.Form): [wtforms.validators.Required(), wtforms.validators.Length(min=6, max=30)], id="password") + + +class ChangeEmailForm(wtforms.Form): + new_email = wtforms.TextField( + _('New email address'), + [wtforms.validators.Required(), + normalize_user_or_email_field(allow_user=False)]) + password = wtforms.PasswordField( + _('Password'), + [wtforms.validators.Required()], + description=_( + "Enter your password to prove you own this account.")) diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index 3592f708..75f5a6d8 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -28,3 +28,5 @@ add_route('mediagoblin.edit.pass', '/edit/password/', 'mediagoblin.edit.views:change_pass') add_route('mediagoblin.edit.verify_email', '/edit/verify_email/', 'mediagoblin.edit.views:verify_email') +add_route('mediagoblin.edit.email', '/edit/email/', + 'mediagoblin.edit.views:change_email') diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 6aa2acd9..82cec8da 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -425,30 +425,52 @@ def verify_email(request): user=user.username) -def _update_email(request, form, user): - new_email = form.new_email.data - users_with_email = User.query.filter_by( - email=new_email).count() - - if users_with_email: - form.new_email.errors.append( - _('Sorry, a user with that email address' - ' already exists.')) - - elif not users_with_email: - verification_key = get_timed_signer_url( - 'mail_verification_token').dumps({ - 'user': user.id, - 'email': new_email}) - - rendered_email = render_template( - request, 'mediagoblin/edit/verification.txt', - {'username': user.username, - 'verification_url': EMAIL_VERIFICATION_TEMPLATE.format( - uri=request.urlgen('mediagoblin.edit.verify_email', - qualified=True), - verification_key=verification_key)}) - - email_debug_message(request) - auth_tools.send_verification_email(user, request, new_email, - rendered_email) +def change_email(request): + """ View to change the user's email """ + form = forms.ChangeEmailForm(request.form) + user = request.user + + # If no password authentication, no need to enter a password + if 'pass_auth' not in request.template_env.globals or not user.pw_hash: + form.__delitem__('password') + + if request.method == 'POST' and form.validate(): + new_email = form.new_email.data + users_with_email = User.query.filter_by( + email=new_email).count() + + if users_with_email: + form.new_email.errors.append( + _('Sorry, a user with that email address' + ' already exists.')) + + if user.pw_hash and not auth.check_password( + form.password.data, user.pw_hash): + form.password.errors.append( + _('Wrong password')) + + if not form.errors: + verification_key = get_timed_signer_url( + 'mail_verification_token').dumps({ + 'user': user.id, + 'email': new_email}) + + rendered_email = render_template( + request, 'mediagoblin/edit/verification.txt', + {'username': user.username, + 'verification_url': EMAIL_VERIFICATION_TEMPLATE.format( + uri=request.urlgen('mediagoblin.edit.verify_email', + qualified=True), + verification_key=verification_key)}) + + email_debug_message(request) + auth_tools.send_verification_email(user, request, new_email, + rendered_email) + + return redirect(request, 'mediagoblin.edit.account') + + return render_to_response( + request, + 'mediagoblin/edit/change_email.html', + {'form': form, + 'user': user}) -- cgit v1.2.3 From 5a6e4e13076afddeeec31259eaee7c5af0defb2d Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Fri, 12 Jul 2013 12:27:41 -0700 Subject: check for form.password in the off chance that a user is logged in and the server switches the authentication method from basic_auth to openid. --- mediagoblin/edit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/edit') diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 82cec8da..53a63cd0 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -444,7 +444,7 @@ def change_email(request): _('Sorry, a user with that email address' ' already exists.')) - if user.pw_hash and not auth.check_password( + if form.password and user.pw_hash and not auth.check_password( form.password.data, user.pw_hash): form.password.errors.append( _('Wrong password')) -- cgit v1.2.3 From dd57c6c5e51a62875542446e0432f850f0239ef8 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Sat, 31 Aug 2013 13:45:58 -0700 Subject: didn't remove form.new_email when change email was moved to its own view --- mediagoblin/edit/views.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'mediagoblin/edit') diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index b09f8c5e..be19bcda 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -237,17 +237,13 @@ def edit_account(request): user.license_preference = form.license_preference.data - if form.new_email.data: - _update_email(request, form, user) - - if not form.errors: - user.save() - messages.add_message(request, - messages.SUCCESS, - _("Account settings saved")) - return redirect(request, - 'mediagoblin.user_pages.user_home', - user=user.username) + user.save() + messages.add_message(request, + messages.SUCCESS, + _("Account settings saved")) + return redirect(request, + 'mediagoblin.user_pages.user_home', + user=user.username) return render_to_response( request, -- cgit v1.2.3 From 560fd63843323483fbd9c137793baed9871c6037 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Wed, 4 Sep 2013 14:54:00 +0200 Subject: Improve checkbox description Do not Enable/Disable next to a checkbox. So what does an enabled checkbox do then? --- mediagoblin/edit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/edit') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 3f1e2386..388940b4 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -64,7 +64,7 @@ class EditAccountForm(wtforms.Form): wants_comment_notification = wtforms.BooleanField( description=_("Email me when others comment on my media")) wants_notifications = wtforms.BooleanField( - description=_("Enable/Disable insite notifications")) + description=_("Enable insite notifications about events.")) license_preference = wtforms.SelectField( _('License preference'), [ -- cgit v1.2.3