1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/services/recaptcha_service.rb
2020-05-27 16:35:30 +02:00

32 lines
724 B
Ruby

# frozen_string_literal: true
# Provides methods to verify the client captcha on Google's services
class RecaptchaService
class << self
def verify(client_response)
return { 'success' => true } unless recaptcha_enabled?
require 'uri'
require 'net/http'
data = { secret: secret_key, response: client_response }
url = URI.parse('https://www.google.com/recaptcha/api/siteverify')
res = Net::HTTP.post_form(url, data)
JSON.parse(res&.body)
end
def recaptcha_enabled?
secret_key.present? && site_key.present?
end
def secret_key
Setting.get('recaptcha_secret_key')
end
def site_key
Setting.get('recaptcha_site_key')
end
end
end