From 744daa6c0cc87e3ed655c1d4ed032e6afd003db1 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 24 Jan 2014 13:52:43 -0500 Subject: [PATCH] When email change fails, give appropriate error message Previously it would always say "Password was incorrect" on failure, whether that was the actual problem or not. --- .../maintenance/user/email_changes_controller.rb | 9 +++++---- app/logical/user_email_change.rb | 2 +- app/views/users/edit.html.erb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/maintenance/user/email_changes_controller.rb b/app/controllers/maintenance/user/email_changes_controller.rb index 161f4bd10..1199c1e16 100644 --- a/app/controllers/maintenance/user/email_changes_controller.rb +++ b/app/controllers/maintenance/user/email_changes_controller.rb @@ -6,11 +6,12 @@ module Maintenance def create email_change = UserEmailChange.new(CurrentUser.user, params[:email_change][:email], params[:email_change][:password]) - if email_change.process - redirect_to(edit_user_path(CurrentUser.user.id), :notice => "Email was updated") + email_change.process + if CurrentUser.user.errors.any? + flash[:notice] = CurrentUser.user.errors.full_messages.join("; ") + redirect_to(new_maintenance_user_email_change_path) else - flash[:notice] = "Password was incorrect" - render :action => "new" + redirect_to(edit_user_path(CurrentUser.user.id), :notice => "Email was updated") end end end diff --git a/app/logical/user_email_change.rb b/app/logical/user_email_change.rb index 432ad2b37..d9a694e0b 100644 --- a/app/logical/user_email_change.rb +++ b/app/logical/user_email_change.rb @@ -9,7 +9,7 @@ class UserEmailChange def process if User.authenticate(user.name, password).nil? - false + user.errors[:base] << "Password was incorrect" else user.email = new_email user.save diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 41e8ea4c4..b4898e953 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -3,7 +3,7 @@

Settings

<%= simple_form_for @user do |f| %> -

<%= link_to "Basic settings", "#basic-settings", :class => 'active' %> | <%= link_to "Advanced settings", "#advanced-settings" %> | <%= link_to "Change password", "#change-password" %> | <%= link_to "Delete account", maintenance_user_deletion_path, :id => "delete-account" %>

+

<%= link_to "Basic settings", "#basic-settings", :class => "active" %> | <%= link_to "Advanced settings", "#advanced-settings" %> | <%= link_to "Change password", "#change-password" %> | <%= link_to "Delete account", maintenance_user_deletion_path, :id => "delete-account" %>