diff --git a/app/assets/locales/en.json b/app/assets/locales/en.json index 118fe21db23471ac7f2bed3551b704876a3abf84..9141ece7723d930fd6ebabe6d7e6c80b6c465d8a 100644 --- a/app/assets/locales/en.json +++ b/app/assets/locales/en.json @@ -367,7 +367,8 @@ }, "users": { "invalid_invite": "Your invitation token is either invalid or incorrect. Please contact your administrator to receive a new one", - "email_exists": "An account under this email already exists. Please try again with another email" + "email_exists": "An account under this email already exists. Please try again with another email", + "old_password": "The current password you have entered is incorrect" }, "rooms": { "room_limit": "Room can not be created due to room limit being reached" diff --git a/app/controllers/api/v1/rooms_controller.rb b/app/controllers/api/v1/rooms_controller.rb index 7ad2ebe0c065b299df6bcb12473e028b9120da7f..55124df2e9a962e0d8d3c7596fde182e8dc371e2 100644 --- a/app/controllers/api/v1/rooms_controller.rb +++ b/app/controllers/api/v1/rooms_controller.rb @@ -66,7 +66,7 @@ module Api # POST /api/v1/rooms.json # Creates a room for the specified user if they are allowed to def create - return render_error status: :bad_request, errors: 'RoomLimitError' unless PermissionsChecker.new( + return render_error status: :bad_request, errors: Rails.configuration.custom_error_msgs[:room_limit] unless PermissionsChecker.new( permission_names: 'RoomLimit', user_id: room_params[:user_id], current_user:, current_provider: ).call diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 8ec79f1fe420df9e08ab101cfb5e40006a87b576..b66a72e6cc6677567dee6b2843ee15235d52c1db 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -111,7 +111,10 @@ module Api return render_error status: :bad_request if new_password.blank? || old_password.blank? - return render_error status: :bad_request unless current_user.authenticate old_password + unless current_user.authenticate old_password + return render_error status: :bad_request, + errors: Rails.configuration.custom_error_msgs[:incorrect_old_password] + end current_user.update! password: new_password render_data status: :ok diff --git a/app/javascript/hooks/mutations/users/useChangePwd.jsx b/app/javascript/hooks/mutations/users/useChangePwd.jsx index d1e0d63048f465b7bd19a7659d993d10af3722f3..b21f8b2fe8967870443661c08b921dc447ab9604 100644 --- a/app/javascript/hooks/mutations/users/useChangePwd.jsx +++ b/app/javascript/hooks/mutations/users/useChangePwd.jsx @@ -12,8 +12,12 @@ export default function useChangePwd() { onSuccess: () => { toast.success(t('toast.success.user.password_updated')); }, - onError: () => { - toast.error(t('toast.error.problem_completing_action')); + onError: (err) => { + if (err.response.data.errors === 'IncorrectOldPassword') { + toast.error(t('toast.error.users.old_password')); + } else { + toast.error(t('toast.error.problem_completing_action')); + } }, }, ); diff --git a/config/application.rb b/config/application.rb index 3122a3b1c5f8a784218f687620a3dab67cc27725..1f19764c315ef5661be43f6bba580f212c6667dc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -29,7 +29,9 @@ module Greenlight email_exists: 'EmailAlreadyExists', record_invalid: 'RecordInvalid', invite_token_invalid: 'InviteInvalid', - hcaptcha_invalid: 'HCaptchaInvalid' + hcaptcha_invalid: 'HCaptchaInvalid', + incorrect_old_password: 'IncorrectOldPassword', + room_limit: 'RoomLimitError' } ActiveModelSerializers.config.adapter = :json