From e1937fdb8b0f5e7a695a39ed5a97241601da18fe Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 11 Aug 2014 10:01:03 +0200 Subject: [PATCH] SONAR-3679 Make the password checking consistent between the "My Profile" and "Users" pages --- .../WEB-INF/app/controllers/account_controller.rb | 15 +++++---------- .../WEB-INF/app/controllers/users_controller.rb | 2 +- .../main/resources/org/sonar/l10n/core.properties | 1 - 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/account_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/account_controller.rb index a90cd7539b2..828d0f3f840 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/account_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/account_controller.rb @@ -43,17 +43,12 @@ class AccountController < ApplicationController def change_password verify_post_request if User.authenticate(current_user.login, params[:old_password], servlet_request) - if ((params[:password] == params[:password_confirmation])) - current_user.password = params[:password] - current_user.password_confirmation = params[:password] - @result = current_user.save - if @result - flash[:notice] = message('my_profile.password.changed') - else - flash[:error] = message('my_profile.password.empty') - end + if params[:password].blank? + flash[:error] = message('my_profile.password.empty') + elsif current_user.update_attributes(:password => params[:password], :password_confirmation => params[:password_confirmation]) + flash[:notice] = message('my_profile.password.changed') else - flash[:error] = message('my_profile.password.mismatch') + flash[:error] = current_user.errors.full_messages.join("
\n") end else flash[:error] = message('my_profile.password.wrong_old') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/users_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/users_controller.rb index 11e17ff729e..ba549b36f7b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/users_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/users_controller.rb @@ -120,7 +120,7 @@ class UsersController < ApplicationController user = User.find(params[:id]) @user = user if params[:user][:password].blank? - @errors = 'Password required.' + @errors = message('my_profile.password.empty') render :partial => 'users/change_password_form', :status => 400 elsif user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation]) flash[:notice] = 'Password was successfully updated.' diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 15d31e7e06c..96d85b86381 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1926,7 +1926,6 @@ my_profile.password.confirm=Confirm new value my_profile.password.submit=Change password my_profile.password.changed=Password changed my_profile.password.empty=Password can not be empty -my_profile.password.mismatch=Password mismatch my_profile.password.wrong_old=Wrong old password my_profile.notifications.submit=Save changes my_profile.overall_notifications.title=Overall notifications -- 2.39.5