Set user instance var for settings routes where needed

This commit is contained in:
Râu Cao
2023-05-27 19:58:59 +02:00
parent 193a4c2edd
commit 32d1992632
2 changed files with 8 additions and 8 deletions

View File

@@ -2,17 +2,16 @@ class SettingsController < ApplicationController
before_action :authenticate_user!
before_action :set_main_nav_section
before_action :set_settings_section, only: [:show, :update, :update_email]
before_action :set_user, only: [:show, :update, :update_email]
def index
redirect_to setting_path(:profile)
end
def show
@user = current_user
end
def update
@user = current_user
@user.preferences.merge! user_params[:preferences]
@user.save!
@@ -22,15 +21,13 @@ 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]
if @user.valid_ldap_authentication?(email_params[:current_password])
if @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
@validation_errors = @user.errors
render :show, status: :unprocessable_entity
end
else
@@ -68,6 +65,9 @@ class SettingsController < ApplicationController
:xmpp_exchange_contacts_with_invitees
])
end
def set_user
@user = current_user
end
def email_params
params.require(:user).permit(:email, :current_password)