-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oleg Hasjanov
authored and
Oleg Hasjanov
committed
Jan 31, 2024
1 parent
dfa2281
commit 2b4179a
Showing
6 changed files
with
67 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Api | ||
module V1 | ||
module Profiles | ||
class PasswordsController < ApplicationController | ||
before_action :authenticate_user! | ||
respond_to :json | ||
|
||
skip_before_action :verify_authenticity_token | ||
|
||
def update | ||
puts params_for_update | ||
|
||
if current_user.valid_password?(params[:user][:current_password]) | ||
if current_user.update(params_for_update) | ||
bypass_sign_in(current_user) | ||
render json: current_user, status: :ok | ||
else | ||
Rails.logger.info current_user.errors.inspect | ||
render json: current_user.errors, status: :unprocessable_entity | ||
end | ||
else | ||
render json: { errors: [t('.incorrect_password')] }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def params_for_update | ||
params.require(:user).permit(:password, :password_confirmation) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Api | ||
module V1 | ||
class ProfilesController < ApplicationController | ||
before_action :authenticate_user! | ||
respond_to :json | ||
|
||
skip_before_action :verify_authenticity_token | ||
|
||
def update | ||
if current_user.update(params_for_update) | ||
render json: current_user, status: :ok | ||
else | ||
Rails.logger.info @user.errors.inspect | ||
render json: current_user.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def params_for_update | ||
params.require(:user).permit(:email, :country_code, :given_names, :surname, :mobile_phone) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters