Merge pull request 'Allow updating one's email address on the account settings page' (#127) from feature/103-update_email into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #127
Reviewed-by: greg <greg@noreply.kosmos.org>
This commit was merged in pull request #127.
This commit is contained in:
2023-05-26 18:07:07 +00:00
24 changed files with 274 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
class SettingsController < ApplicationController
before_action :authenticate_user!
before_action :set_main_nav_section
before_action :set_settings_section, only: ['show', 'update']
before_action :set_settings_section, only: [:show, :update, :update_email]
def index
redirect_to setting_path(:profile)
@@ -21,6 +21,25 @@ class SettingsController < ApplicationController
}
end
def update_email
if current_user.valid_ldap_authentication?(email_params[:current_password])
current_user.email = email_params[:email]
if current_user.update email: email_params[:email]
redirect_to setting_path(:account), flash: {
notice: 'Please confirm your new address using the confirmation link we just sent you.'
}
else
@validation_errors = current_user.errors
render :show, status: :unprocessable_entity
end
else
redirect_to setting_path(:account), flash: {
error: 'Password did not match your current password. Try again.'
}
end
end
def reset_password
current_user.send_reset_password_instructions
sign_out current_user
@@ -49,4 +68,8 @@ class SettingsController < ApplicationController
:xmpp_exchange_contacts_with_invitees
])
end
def email_params
params.require(:user).permit(:email, :current_password)
end
end