Allow email address updates on account settings page
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Râu Cao
2023-05-25 16:58:53 +02:00
parent b1a693e7cf
commit 134c81460a
9 changed files with 188 additions and 17 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