2019-12-10 04:59:35 +00:00
|
|
|
class Api::V1::ProfilesController < Api::BaseController
|
2020-02-16 11:50:38 +00:00
|
|
|
before_action :set_user
|
2019-12-10 04:59:35 +00:00
|
|
|
|
|
|
|
def show
|
2020-05-31 17:40:20 +00:00
|
|
|
render partial: 'api/v1/models/user.json.jbuilder', locals: { resource: @user }
|
2019-12-10 04:59:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2021-06-02 12:22:24 +00:00
|
|
|
if password_params[:password].present?
|
|
|
|
render_could_not_create_error('Invalid current password') and return unless @user.valid_password?(password_params[:current_password])
|
|
|
|
|
|
|
|
@user.update!(password_params.except(:current_password))
|
|
|
|
end
|
|
|
|
|
2019-12-10 04:59:35 +00:00
|
|
|
@user.update!(profile_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-16 11:50:38 +00:00
|
|
|
def set_user
|
2019-12-10 04:59:35 +00:00
|
|
|
@user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def profile_params
|
2020-07-27 16:49:26 +00:00
|
|
|
params.require(:profile).permit(
|
|
|
|
:email,
|
|
|
|
:name,
|
|
|
|
:display_name,
|
|
|
|
:avatar,
|
2021-01-10 13:55:33 +00:00
|
|
|
:availability,
|
|
|
|
ui_settings: {}
|
2020-07-27 16:49:26 +00:00
|
|
|
)
|
2019-12-10 04:59:35 +00:00
|
|
|
end
|
2021-06-02 12:22:24 +00:00
|
|
|
|
|
|
|
def password_params
|
|
|
|
params.require(:profile).permit(
|
|
|
|
:current_password,
|
|
|
|
:password,
|
|
|
|
:password_confirmation
|
|
|
|
)
|
|
|
|
end
|
2019-12-10 04:59:35 +00:00
|
|
|
end
|