1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-15 00:24:09 +01:00
fab-manager/app/services/recaptcha_service.rb

32 lines
724 B
Ruby
Raw Normal View History

# 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
2020-05-27 16:35:30 +02:00
Setting.get('recaptcha_secret_key')
end
def site_key
2020-05-27 16:35:30 +02:00
Setting.get('recaptcha_site_key')
end
end
2020-05-27 16:35:30 +02:00
end