Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 470
- Log:
Version 1.0.2 with updated reCaptcha
- Author:
- rool
- Date:
- Sat Apr 16 11:20:56 +0100 2016
- Size:
- 2270 Bytes
1 | require 'recaptcha/configuration' |
2 | require 'recaptcha/client_helper' |
3 | require 'recaptcha/verify' |
4 | require 'recaptcha/token' |
5 | require 'uri' |
6 | require 'net/http' |
7 | |
8 | module Recaptcha |
9 | CONFIG = { |
10 | 'server_url' => '//www.google.com/recaptcha/api.js', |
11 | 'secure_server_url' => 'https://www.google.com/recaptcha/api.js', |
12 | 'verify_url' => 'https://www.google.com/recaptcha/api/siteverify' |
13 | } |
14 | |
15 | USE_SSL_BY_DEFAULT = false |
16 | HANDLE_TIMEOUTS_GRACEFULLY = true |
17 | SKIP_VERIFY_ENV = ['test', 'cucumber'] |
18 | DEFAULT_TIMEOUT = 3 |
19 | |
20 | # Gives access to the current Configuration. |
21 | def self.configuration |
22 | @configuration ||= Configuration.new |
23 | end |
24 | |
25 | # Allows easy setting of multiple configuration options. See Configuration |
26 | # for all available options. |
27 | #-- |
28 | # The temp assignment is only used to get a nicer rdoc. Feel free to remove |
29 | # this hack. |
30 | #++ |
31 | def self.configure |
32 | config = configuration |
33 | yield(config) |
34 | end |
35 | |
36 | def self.with_configuration(config) |
37 | original_config = {} |
38 | |
39 | config.each do |key, value| |
40 | original_config[key] = configuration.send(key) |
41 | configuration.send("#{key}=", value) |
42 | end |
43 | |
44 | result = yield if block_given? |
45 | |
46 | original_config.each { |key, value| configuration.send("#{key}=", value) } |
47 | result |
48 | end |
49 | |
50 | def self.get(verify_hash, options) |
51 | http = if Recaptcha.configuration.proxy |
52 | proxy_server = URI.parse(Recaptcha.configuration.proxy) |
53 | Net::HTTP::Proxy(proxy_server.host, proxy_server.port, proxy_server.user, proxy_server.password) |
54 | else |
55 | Net::HTTP |
56 | end |
57 | query = URI.encode_www_form(verify_hash) |
58 | uri = URI.parse(Recaptcha.configuration.verify_url + '?' + query) |
59 | http_instance = http.new(uri.host, uri.port) |
60 | http_instance.read_timeout = http_instance.open_timeout = options[:timeout] || DEFAULT_TIMEOUT |
61 | if uri.port == 443 |
62 | http_instance.use_ssl = true |
63 | http_instance.verify_mode = OpenSSL::SSL::VERIFY_NONE |
64 | end |
65 | request = Net::HTTP::Get.new(uri.request_uri) |
66 | http_instance.request(request).body |
67 | end |
68 | |
69 | def self.i18n(key, default) |
70 | if defined?(I18n) |
71 | I18n.translate(key, :default => default) |
72 | else |
73 | default |
74 | end |
75 | end |
76 | |
77 | |
78 | class RecaptchaError < StandardError |
79 | end |
80 | |
81 | class VerifyError < RecaptchaError |
82 | end |
83 | end |