Class: Api::V1::RegistrationsController

Inherits:
ActionController::API
  • Object
show all
Includes:
Usman::ApiHelper
Defined in:
app/controllers/api/v1/registrations_controller.rb

Instance Method Summary collapse

Methods included from Usman::ApiHelper

#current_user, #embed_stack_in_json_response?, #render_json_response, #require_admin_auth_token, #require_auth_token, #require_super_admin_auth_token

Instance Method Details

#registerObject



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

def register
  proc_code = Proc.new do
    @reg_data = Usman::MobileRegistrationService.new(params)
    @errors = @reg_data.errors
    @success = false
    if @errors[:heading].blank?
      @success = true
      @alert = {
        heading: I18n.translate("mobile_registration.otp_sent.heading"),
        message: I18n.translate("mobile_registration.otp_sent.message")
      }
      @data = {
                registration: @reg_data.registration,
                device: @reg_data.device
              }
    end
  end
  render_json_response(proc_code)
end

#resend_otpObject



27
28
29
30
31
32
# File 'app/controllers/api/v1/registrations_controller.rb', line 27

def resend_otp
  proc_code = Proc.new do

  end
  render_json_response(proc_code)
end

#verifyObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/api/v1/registrations_controller.rb', line 34

def verify
  proc_code = Proc.new do
    @device = Device.where("uuid = ?", params[:uuid]).first
    if @device
      if @device.blocked?
        @success = false
        @errors = {
          heading: I18n.translate("mobile_registration.device_blocked.heading"),
          message: I18n.translate("mobile_registration.device_blocked.message"),
          details: {}
        }
      else
        valid, validation_errors = @device.validate_otp(params[:otp], params[:dialing_prefix], params[:mobile_number])
        if valid
          @success = true
          @alert = {
            heading: I18n.translate("mobile_registration.verification_success.heading"),
            message: I18n.translate("mobile_registration.verification_success.message")
          }
          @data = { api_token: @device.api_token }
        else
          @success = false
          @errors = {
            heading: I18n.translate("mobile_registration.otp_not_matching.heading"),
            message: I18n.translate("mobile_registration.otp_not_matching.message"),
            details: validation_errors
          }
        end
      end
    else
      @success = false
      @errors = {
        heading: I18n.translate("general.unexpected_failure.heading"),
        message: I18n.translate("general.unexpected_failure.message"),
        details: {
          uuid: "is invalid"
        }
      }
    end
  end
  render_json_response(proc_code)
end