2023-05-31 23:49:19 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class ProfileController < ApplicationController
|
2023-09-17 00:45:57 +03:00
|
|
|
before_action do
|
|
|
|
|
authorize!(:manage, current_user)
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-20 23:42:56 +03:00
|
|
|
def index; end
|
|
|
|
|
|
2023-06-07 01:36:47 +03:00
|
|
|
def update_contact
|
|
|
|
|
if current_user.update(contact_params)
|
2025-11-26 14:12:08 +02:00
|
|
|
if current_user.try(:pending_reconfirmation?) && current_user.previous_changes.key?(:unconfirmed_email)
|
2025-11-30 16:00:13 +02:00
|
|
|
SendConfirmationInstructionsJob.perform_async('user_id' => current_user.id)
|
|
|
|
|
|
2025-11-26 14:12:08 +02:00
|
|
|
redirect_to settings_profile_index_path,
|
|
|
|
|
notice: I18n.t('a_confirmation_email_has_been_sent_to_the_new_email_address')
|
|
|
|
|
else
|
|
|
|
|
redirect_to settings_profile_index_path, notice: I18n.t('contact_information_has_been_update')
|
|
|
|
|
end
|
2023-06-07 01:36:47 +03:00
|
|
|
else
|
2025-08-14 09:25:35 +03:00
|
|
|
render :index, status: :unprocessable_content
|
2023-06-07 01:36:47 +03:00
|
|
|
end
|
2023-05-31 23:49:19 +03:00
|
|
|
end
|
|
|
|
|
|
2023-06-07 01:36:47 +03:00
|
|
|
def update_password
|
2025-09-05 21:48:22 +03:00
|
|
|
if current_user.update_with_password(password_params)
|
2023-06-07 01:36:47 +03:00
|
|
|
bypass_sign_in(current_user)
|
2024-09-18 19:47:47 +03:00
|
|
|
redirect_to settings_profile_index_path, notice: I18n.t('password_has_been_changed')
|
2023-06-20 23:42:56 +03:00
|
|
|
else
|
2025-08-14 09:25:35 +03:00
|
|
|
render :index, status: :unprocessable_content
|
2023-06-20 23:42:56 +03:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-31 23:49:19 +03:00
|
|
|
private
|
|
|
|
|
|
2023-06-07 01:36:47 +03:00
|
|
|
def contact_params
|
2023-06-30 01:26:13 +03:00
|
|
|
params.require(:user).permit(:first_name, :last_name, :email)
|
2023-06-07 01:36:47 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def password_params
|
2025-09-05 21:48:22 +03:00
|
|
|
params.require(:user).permit(:password, :password_confirmation, :current_password)
|
2023-05-31 23:49:19 +03:00
|
|
|
end
|
|
|
|
|
end
|