Skip to content

Commit

Permalink
feat: update user controller, active uuid for new user (LINCnil#226)
Browse files Browse the repository at this point in the history
* feat: update user controller, active uuid for new user

* fix: fix password-forgotten 404 return

* lint: remove shorthand rule

* fix: fix for optionnaly check access locked?

---------

Co-authored-by: Sylvain Pastor <sylvain@mbpdeatnosadmin.home>
  • Loading branch information
syl-p and Sylvain Pastor authored Jan 4, 2024
1 parent f24a10b commit d817dab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Style/Documentation:
Enabled: false
Layout/LineLength:
Max: 140
EnforcedShorthandSyntax: never
19 changes: 8 additions & 11 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,23 @@ def update
def check_uuid
user = User.find_by(uuid: params[:uuid])
return head :not_found unless user
return head :not_acceptable unless user.access_locked? || (params[:reset].present? && !user.access_locked?)

# render user data
render json: serialize(user)
end

def password_forgotten
user = User.find_by(email: params[:email])
return head :not_found unless user

if user.present?
if user.access_locked?
render json: {}, status: :locked
elsif user.valid?
user.save
UserMailer.with(user: user).uuid_updated.deliver_now
render json: {} # change uuid
else
render json: {}, status: :not_acceptable # Not acceptable
end
if user.access_locked?
render json: {}, status: :locked
else
render json: {}, status: :not_found
user.generate_uuid
user.save
UserMailer.with(user: user).uuid_updated.deliver_now
render json: {} # change uuid
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

resources :users do
collection do
get 'unlock_access/:uuid', to: 'users#check_uuid'
get 'unlock_access/:uuid(/:reset)', to: 'users#check_uuid'
post 'password-forgotten', to: 'users#password_forgotten'
put 'change-password', to: 'users#change_password'
end
Expand Down

0 comments on commit d817dab

Please sign in to comment.