Changesets can be listed by changeset number.
The Git repository is here.
Changeset 470
Version 1.0.2 with updated reCaptcha
- Comitted by: rool
- Date: Saturday April 16 11:20:56 2016 (over 8 years ago)
Affected files:
- rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/token.rb
- rool/rails/hub/trunk/CHANGELOG (diff)
- rool/rails/hub/trunk/VERSION (diff)
- rool/rails/hub/trunk/app/controllers/account_controller.rb (diff)
- rool/rails/hub/trunk/app/views/stylesheets/hub.css.erb (diff)
- rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha.rb (diff)
- rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/client_helper.rb (diff)
- rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/configuration.rb (diff)
- rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/railtie.rb (diff)
- rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/verify.rb (diff)
rool/rails/hub/trunk/CHANGELOG:
prev. | current | |
1 | 1.0.2 (16-Apr-2016) | |
2 | =================== | |
3 | ||
4 | Updated and customised reCaptcha code for V2 Google reCaptcha use. | |
5 | ||
6 | ||
1.0.1 (30-Aug-2011) | ||
=================== | ||
rool/rails/hub/trunk/VERSION:
prev. | current | |
1 | ||
1 | 1.0.2 (16-Apr-2016) |
rool/rails/hub/trunk/app/controllers/account_controller.rb:
prev. | current | |
# don't want to successfully save a model only to find that the captcha | ||
# text is incorrect. | ||
125 | | |
126 | | |
127 | | |
128 | | |
125 | begin | |
126 | success = verify_recaptcha( | |
127 | :model => @user, | |
128 | :message => "The reCaptcha challenge wasn't happy with the response. Please try again or contact RISC OS Open for assistance." | |
129 | ) | |
130 | rescue => e | |
131 | Rails.logger.error(e.inspect) | |
132 | hubssolib_set_flash(:attention, 'The reCaptcha system is currently not available and cannot verify signups. Please try again later.') | |
133 | redirect_to :controller => 'tasks', :action => nil | |
134 | return | |
135 | end | |
137 | raise ActiveRecord::RecordInvalid.new(@user) if not success | |
138 | ||
@user.roles = HubSsoLib::Roles.new(false).to_s | ||
@user.save! | ||
... | ... | |
@title = 'User account details' | ||
@user = User.find(params[:id]) | ||
@referrer = request.env["HTTP_REFERER"] | ||
361 | | |
370 | @referrer = nil unless (@referrer && !@referrer.empty?) | |
end | ||
def edit_roles |
rool/rails/hub/trunk/app/views/stylesheets/hub.css.erb:
prev. | current | |
* Suggested by M.Drake, 2011-03-18: | ||
* | ||
* https://www.riscosopen.org/forum/forums/1/topics/591?page=2 | ||
121 | * | |
122 | * 2016-04-16 (ADH): Disabled as it seems much better at this now. | |
*/ | ||
123 | ||
125 | /*a.image img | |
{ | ||
display: inline-block; | ||
} | ||
129 | */ | |
130 | ||
131 | /*****************************************************************************\ | |
132 | * Browser-specific styles: Google reCaptcha bugs - the 'noscript' version is | |
133 | * pretty badly broken. | |
134 | \*****************************************************************************/ | |
135 | ||
136 | noscript textarea#g-recaptcha-response | |
137 | { | |
138 | display: none; | |
139 | } |
rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha.rb:
prev. | current | |
require 'recaptcha/configuration' | ||
require 'recaptcha/client_helper' | ||
require 'recaptcha/verify' | ||
4 | require 'recaptcha/token' | |
5 | require 'uri' | |
6 | require 'net/http' | |
module Recaptcha | ||
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
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 | } | |
12 | | |
13 | | |
14 | ||
15 | ||
16 | | |
17 | | |
18 | | |
19 | ||
15 | USE_SSL_BY_DEFAULT = false | |
16 | HANDLE_TIMEOUTS_GRACEFULLY = true | |
SKIP_VERIFY_ENV = ['test', 'cucumber'] | ||
18 | DEFAULT_TIMEOUT = 3 | |
# Gives access to the current Configuration. | ||
def self.configuration | ||
... | ... | |
result | ||
end | ||
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 | ||
class RecaptchaError < StandardError | ||
end | ||
54 | ||
56 | ||
57 | | |
81 | class VerifyError < RecaptchaError | |
82 | end | |
end |
rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/client_helper.rb:
prev. | current | |
# Your public API can be specified in the +options+ hash or preferably | ||
# using the Configuration. | ||
def recaptcha_tags(options = {}) | ||
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
11 | | |
12 | | |
13 | | |
14 | | |
15 | | |
6 | public_key = options[:public_key] || Recaptcha.configuration.public_key! | |
7 | ||
8 | script_url = Recaptcha.configuration.api_server_url(options[:ssl]) | |
9 | script_url += "?hl=#{options[:hl]}" unless options[:hl].to_s == "" | |
10 | fallback_uri = "#{script_url.chomp('.js')}/fallback?k=#{public_key}" | |
11 | ||
12 | data_attributes = [:theme, :type, :callback, :expired_callback, :size] | |
13 | data_attributes = options.each_with_object({}) do |(k, v), a| | |
14 | a[k] = v if data_attributes.include?(k) | |
end | ||
17 | | |
18 | | |
19 | | |
20 | | |
21 | | |
22 | | |
23 | | |
24 | | |
25 | | |
26 | | |
27 | | |
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
38 | | |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | |
44 | | |
45 | | |
46 | | |
16 | data_attributes[:sitekey] = public_key | |
17 | data_attributes[:stoken] = Recaptcha::Token.secure_token if options[:stoken] != false | |
18 | data_attributes = data_attributes.map { |k,v| %{data-#{k.to_s.tr('_','-')}="#{v}"} }.join(" ") | |
19 | ||
20 | html = %{<script src="#{script_url}" async defer></script>\n} | |
21 | html << %{<div class="g-recaptcha" #{data_attributes}></div>\n} | |
22 | ||
23 | if options[:noscript] != false | |
24 | html << <<-HTML | |
25 | <noscript> | |
26 | <div style="width: 302px; height: 352px;"> | |
27 | <div style="width: 302px; height: 352px; position: relative;"> | |
28 | <div style="width: 302px; height: 352px; position: absolute;"> | |
29 | <iframe | |
30 | src="#{fallback_uri}" | |
31 | frameborder="0" scrolling="no" | |
32 | style="width: 302px; height:352px; border-style: none;"> | |
33 | </iframe> | |
34 | </div> | |
35 | <div style="width: 250px; height: 80px; position: absolute; border-style: none; | |
36 | bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;"> | |
37 | <textarea id="g-recaptcha-response" name="g-recaptcha-response" | |
38 | class="g-recaptcha-response" | |
39 | style="width: 250px; height: 80px; border: 1px solid #c1c1c1; | |
40 | margin: 0px; padding: 0px; resize: none;" value=""> | |
41 | </textarea> | |
42 | </div> | |
43 | </div> | |
44 | </div> | |
45 | </noscript> | |
46 | HTML | |
end | ||
48 | | |
49 | | |
50 | | |
51 | ||
48 | ||
49 | html.respond_to?(:html_safe) ? html.html_safe : html | |
50 | end | |
51 | end | |
52 | end | |
rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/configuration.rb:
prev. | current | |
module Recaptcha | ||
# This class enables detailed configuration of the recaptcha services. | ||
3 | | |
3 | # | |
# By calling | ||
# | ||
# Recaptcha.configuration # => instance of Recaptcha::Configuration | ||
... | ... | |
# you are able to perform configuration updates. | ||
# | ||
# Your are able to customize all attributes listed below. All values have | ||
16 | | |
16 | # sensitive default and will very likely not need to be changed. | |
# | ||
# Please note that the public and private key for the reCAPTCHA API Access | ||
# have no useful default value. The keys may be set via the Shell enviroment | ||
... | ... | |
# end | ||
# | ||
class Configuration | ||
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
31 | attr_accessor :skip_verify_env, :private_key, :public_key, :proxy, :handle_timeouts_gracefully, :use_ssl_by_default | |
def initialize #:nodoc: | ||
40 | | |
41 | | |
42 | | |
43 | | |
34 | @skip_verify_env = SKIP_VERIFY_ENV | |
35 | @handle_timeouts_gracefully = HANDLE_TIMEOUTS_GRACEFULLY | |
36 | @use_ssl_by_default = USE_SSL_BY_DEFAULT | |
@private_key = ENV['RECAPTCHA_PRIVATE_KEY'] | ||
@public_key = ENV['RECAPTCHA_PUBLIC_KEY'] | ||
end | ||
49 | | |
50 | | |
42 | def private_key! | |
43 | private_key || raise(RecaptchaError, "No private key specified.") | |
end | ||
45 | ||
46 | def public_key! | |
47 | public_key || raise(RecaptchaError, "No public key specified.") | |
48 | end | |
49 | ||
50 | def api_server_url(ssl) | |
51 | ssl = use_ssl_by_default if ssl.nil? | |
52 | key = (ssl ? 'secure_server_url' : 'server_url') | |
53 | CONFIG.fetch(key) | |
54 | end | |
55 | ||
56 | def verify_url | |
57 | CONFIG.fetch('verify_url') | |
58 | end | |
59 | ||
60 | def api_version=(v) | |
61 | if v == 'v2' | |
62 | warn 'setting api_version is deprecated and will be removed shortly, only v2 is supported' | |
63 | else | |
64 | raise ArgumentError, "only v2 is supported, not #{v.inspect}" | |
65 | end | |
66 | end | |
67 | ||
68 | def api_version | |
69 | warn 'getting api_version is deprecated and will be removed shortly, only v2 is supported' | |
70 | 'v2' | |
71 | end | |
end | ||
53 | ||
73 | end | |
rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/railtie.rb:
prev. | current | |
module Rails | ||
module Recaptcha | ||
class Railtie < Rails::Railtie | ||
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
6 | initializer :recaptcha do | |
7 | ActionView::Base.send(:include, ::Recaptcha::ClientHelper) | |
8 | ActionController::Base.send(:include, ::Recaptcha::Verify) | |
end | ||
end | ||
end |
rool/rails/hub/trunk/vendor/plugins/recaptcha/lib/recaptcha/verify.rb:
prev. | current | |
require "uri" | ||
2 | require "json" | |
3 | ||
module Recaptcha | ||
module Verify | ||
# Your private API can be specified in the +options+ hash or preferably | ||
... | ... | |
if(Recaptcha.configuration.proxy) | ||
proxy_server = URI.parse(Recaptcha.configuration.proxy) | ||
http = Net::HTTP::Proxy(proxy_server.host, proxy_server.port) | ||
23 | | |
24 | | |
25 | raise "Proxy code compatible with HTTPS and Ruby 1.8.7 hasn't been written yet" | |
end | ||
28 | url = URI.parse(Recaptcha.configuration.verify_url) | |
29 | req = Net::HTTP::Post.new(url.request_uri) | |
30 | req.set_form_data({ | |
31 | "secret" => private_key, | |
32 | "remoteip" => request.remote_ip, | |
33 | "response" => params['g-recaptcha-response'] | |
34 | }) | |
35 | http = Net::HTTP.new(url.host, url.port) | |
36 | http.use_ssl = (url.scheme == "https") | |
Timeout::timeout(options[:timeout] || 3) do | ||
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
38 | recaptcha = http.request(req) | |
end | ||
40 | ||
41 | json = JSON.parse(recaptcha.body) rescue {"success" => false} | |
42 | ||
answer, error = recaptcha.body.split.map { |s| s.chomp } | ||
36 | | |
37 | | |
44 | if json['success'] == true | |
45 | return true | |
46 | else | |
if model | ||
message = "Word verification response is incorrect, please try again." | ||
message = I18n.translate(:'recaptcha.errors.verification_failed', {:default => message}) if defined?(I18n) | ||
model.errors.add attribute, options[:message] || message | ||
end | ||
return false | ||
44 | | |
45 | | |
46 | | |
end | ||
rescue Timeout::Error | ||
49 | | |
50 | | |
51 | | |
52 | | |
53 | | |
54 | | |
55 | | |
56 | | |
57 | | |
55 | raise "reCaptcha system is not available (timeout)" | |
end | ||
end # verify_recaptcha | ||
end # Verify |