Module: Auth::Centric::Captcha::CheckCode

Included in:
SecurityCaptcha
Defined in:
lib/auth/centric/captcha/check_code.rb

Instance Method Summary collapse

Instance Method Details

#check_code_path(id) ⇒ Object



35
36
37
# File 'lib/auth/centric/captcha/check_code.rb', line 35

def check_code_path(id)
  [host, "api/v1/security_captchas/#{id}/check_code"].join('/')
end

#verify_code?(id:, code:) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/auth/centric/captcha/check_code.rb', line 7

def verify_code?(id:, code:)
  return true unless enabled?

  payload = {
    security_captcha: {
      ip: @ip_address,
      code:,
      session_id: @session_id
    }
  }

  http = HTTP
           .timeout(timeout_seconds)
           .headers(apikey:)
           .post(check_code_path(id), json: payload)

  case http.status
    when 202
      return true
    when 404, 406
      return false
    else
      raise Error, "#{http.status}: #{http.body}"
  end
rescue HTTP::TimeoutError
  false
end