Set user instance var for settings routes where needed
This commit is contained in:
parent
193a4c2edd
commit
32d1992632
@ -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)
|
||||
|
@ -3,7 +3,7 @@
|
||||
"settings--account--email-validation-failed-value": @validation_errors.present?
|
||||
} do %>
|
||||
<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" %>
|
||||
<p class="mb-2">
|
||||
<%= f.label :email, 'Address', class: 'font-bold' %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user