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
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
2 changed files with 8 additions and 8 deletions

View File

@ -2,17 +2,16 @@ class SettingsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_main_nav_section before_action :set_main_nav_section
before_action :set_settings_section, only: [:show, :update, :update_email] before_action :set_settings_section, only: [:show, :update, :update_email]
before_action :set_user, only: [:show, :update, :update_email]
def index def index
redirect_to setting_path(:profile) redirect_to setting_path(:profile)
end end
def show def show
@user = current_user
end end
def update def update
@user = current_user
@user.preferences.merge! user_params[:preferences] @user.preferences.merge! user_params[:preferences]
@user.save! @user.save!
@ -22,15 +21,13 @@ class SettingsController < ApplicationController
end end
def update_email def update_email
if current_user.valid_ldap_authentication?(email_params[:current_password]) if @user.valid_ldap_authentication?(email_params[:current_password])
current_user.email = email_params[:email] if @user.update email: email_params[:email]
if current_user.update email: email_params[:email]
redirect_to setting_path(:account), flash: { redirect_to setting_path(:account), flash: {
notice: 'Please confirm your new address using the confirmation link we just sent you.' notice: 'Please confirm your new address using the confirmation link we just sent you.'
} }
else else
@validation_errors = current_user.errors @validation_errors = @user.errors
render :show, status: :unprocessable_entity render :show, status: :unprocessable_entity
end end
else else
@ -68,6 +65,9 @@ class SettingsController < ApplicationController
:xmpp_exchange_contacts_with_invitees :xmpp_exchange_contacts_with_invitees
]) ])
end end
def set_user
@user = current_user
end
def email_params def email_params
params.require(:user).permit(:email, :current_password) params.require(:user).permit(:email, :current_password)

View File

@ -3,7 +3,7 @@
"settings--account--email-validation-failed-value": @validation_errors.present? "settings--account--email-validation-failed-value": @validation_errors.present?
} do %> } do %>
<h3>E-Mail</h3> <h3>E-Mail</h3>
<%= form_for(current_user, url: update_email_settings_path, method: "post") do |f| %> <%= form_for(@user, url: update_email_settings_path, method: "post") do |f| %>
<%= hidden_field_tag :section, "account" %> <%= hidden_field_tag :section, "account" %>
<p class="mb-2"> <p class="mb-2">
<%= f.label :email, 'Address', class: 'font-bold' %> <%= f.label :email, 'Address', class: 'font-bold' %>