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)
|
2023-06-30 01:26:13 +03:00
|
|
|
redirect_to settings_profile_index_path, notice: 'Contact information has been updated'
|
2023-06-07 01:36:47 +03:00
|
|
|
else
|
2023-06-07 12:04:11 +03:00
|
|
|
render :index, status: :unprocessable_entity
|
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
|
2023-06-07 12:04:11 +03:00
|
|
|
if current_user.update(password_params)
|
2023-06-07 01:36:47 +03:00
|
|
|
bypass_sign_in(current_user)
|
2023-06-30 01:26:13 +03:00
|
|
|
redirect_to settings_profile_index_path, notice: 'Password has been changed'
|
2023-06-20 23:42:56 +03:00
|
|
|
else
|
|
|
|
|
render :index, status: :unprocessable_entity
|
|
|
|
|
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
|
2023-06-07 12:04:11 +03:00
|
|
|
params.require(:user).permit(:password, :password_confirmation)
|
2023-05-31 23:49:19 +03:00
|
|
|
end
|
|
|
|
|
end
|