Class: Api::V5::PasswordsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v5/passwords_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema

Instance Method Summary collapse

Methods inherited from BaseController

#identity_cache_memoization

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#resetObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/api/v5/passwords_controller.rb', line 6

def reset
  email = params.require(:email)
  recaptcha_token = params[:recaptcha_token]
  client_type = params[:client_type]

  # Only verify reCAPTCHA for web clients
  if client_type == 'web' && !verify_recaptcha(response: recaptcha_token)
    return render json: ResponseSchema.new(data: nil, success: false,
                                           message: 'reCAPTCHA verification failed. Please try again.')
  end

  operation = ResetPasswordService.call(email: email)
  if operation.success?
    render json: ResponseSchema.new(data: nil, success: true,
                                    message: 'You will receive sms and email with new password in a few minutes')
  else
    render json: ResponseSchema.new(data: nil, success: false,
                                    message: operation['result.error_messages']&.to_sentence)
  end
end