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.
This commit is contained in:
@@ -6,11 +6,12 @@ module Maintenance
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
email_change = UserEmailChange.new(CurrentUser.user, params[:email_change][:email], params[:email_change][:password])
|
email_change = UserEmailChange.new(CurrentUser.user, params[:email_change][:email], params[:email_change][:password])
|
||||||
if email_change.process
|
email_change.process
|
||||||
redirect_to(edit_user_path(CurrentUser.user.id), :notice => "Email was updated")
|
if CurrentUser.user.errors.any?
|
||||||
|
flash[:notice] = CurrentUser.user.errors.full_messages.join("; ")
|
||||||
|
redirect_to(new_maintenance_user_email_change_path)
|
||||||
else
|
else
|
||||||
flash[:notice] = "Password was incorrect"
|
redirect_to(edit_user_path(CurrentUser.user.id), :notice => "Email was updated")
|
||||||
render :action => "new"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class UserEmailChange
|
|||||||
|
|
||||||
def process
|
def process
|
||||||
if User.authenticate(user.name, password).nil?
|
if User.authenticate(user.name, password).nil?
|
||||||
false
|
user.errors[:base] << "Password was incorrect"
|
||||||
else
|
else
|
||||||
user.email = new_email
|
user.email = new_email
|
||||||
user.save
|
user.save
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<h1>Settings</h1>
|
<h1>Settings</h1>
|
||||||
|
|
||||||
<%= simple_form_for @user do |f| %>
|
<%= simple_form_for @user do |f| %>
|
||||||
<h2 id="edit-options"><%= 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" %></h2>
|
<h2 id="edit-options"><%= 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" %></h2>
|
||||||
|
|
||||||
<fieldset id="basic-settings-section">
|
<fieldset id="basic-settings-section">
|
||||||
<div class="input">
|
<div class="input">
|
||||||
|
|||||||
Reference in New Issue
Block a user