Module: EdgeAuth

Defined in:
lib/edge-auth.rb,
lib/edge-auth/engine.rb,
lib/edge-auth/version.rb,
app/models/edge_auth/identity.rb,
app/helpers/edge_auth/application_helper.rb,
app/controllers/edge_auth/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper Classes: ApplicationController, Engine, Identity

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.verify_recaptcha(remote_ip, params) ⇒ Object

try and verify the captcha response. Then give out a message to flash



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/edge-auth.rb', line 6

def self.verify_recaptcha(remote_ip, params)
  
  unless EdgeCaptcha::Engine.config.recaptcha[:enable]
    return true
  end

  responce = Net::HTTP.post_form(URI.parse(EdgeCaptcha::Engine.config.recaptcha[:api_server_url]),
    { :privatekey => EdgeCaptcha::Engine.config.recaptcha[:private_key],
      :remoteip => remote_ip,
      :challenge => params[:recaptcha_challenge_field],
      :response => params[:recaptcha_response_field] })
    
  result = { :status => responce.body.split("\n")[0], 
             :error_code => responce.body.split("\n")[1] }

  if result[:error_code] == "incorrect-captcha-sol"
    return false
  elsif result[:error_code] == 'success'
    return true
  else
    flash[:alert] = "There has been a unexpected error with the application. Please contact the administrator. error code: #{result[:error_code]}"
    return false
  end
  return true
end