Commit 11b7bff48a20fa384782b9f2516b2dea4f035f6c
1 parent
eced5f5b
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
captcha server side draft
Showing
2 changed files
with
33 additions
and
8 deletions
Show diff stats
lib/noosfero/api/helpers.rb
| @@ -114,6 +114,7 @@ module Noosfero | @@ -114,6 +114,7 @@ module Noosfero | ||
| 114 | end | 114 | end |
| 115 | 115 | ||
| 116 | def verify_recaptcha_v2(remote_ip, g_recaptcha_response, private_key, api_recaptcha_verify_uri) | 116 | def verify_recaptcha_v2(remote_ip, g_recaptcha_response, private_key, api_recaptcha_verify_uri) |
| 117 | + binding.pry | ||
| 117 | verify_hash = { | 118 | verify_hash = { |
| 118 | "secret" => private_key, | 119 | "secret" => private_key, |
| 119 | "remoteip" => remote_ip, | 120 | "remoteip" => remote_ip, |
| @@ -216,6 +217,26 @@ module Noosfero | @@ -216,6 +217,26 @@ module Noosfero | ||
| 216 | begin_period..end_period | 217 | begin_period..end_period |
| 217 | end | 218 | end |
| 218 | 219 | ||
| 220 | + def verify_recaptcha_v1(remote_ip, recaptcha_response_field, private_key, recaptcha_challenge_field, api_recaptcha_verify_uri) | ||
| 221 | + binding.pry | ||
| 222 | + verify_hash = { | ||
| 223 | + "privatekey" => private_key, | ||
| 224 | + "remoteip" => remote_ip, | ||
| 225 | + "challenge" => recaptcha_challenge_field, | ||
| 226 | + "response" => recaptcha_response_field | ||
| 227 | + } | ||
| 228 | + uri = URI(api_recaptcha_verify_uri) | ||
| 229 | + https = Net::HTTP.new(uri.host, uri.port) | ||
| 230 | + https.use_ssl = true | ||
| 231 | + request = Net::HTTP::Post.new(uri.path) | ||
| 232 | + request.set_form_data(verify_hash) | ||
| 233 | + if https.request(request).body == "true\nsuccess" | ||
| 234 | + captcha_result["success"]=true | ||
| 235 | + else | ||
| 236 | + captcha_result["success"]=false | ||
| 237 | + end | ||
| 238 | + end | ||
| 239 | + | ||
| 219 | end | 240 | end |
| 220 | end | 241 | end |
| 221 | end | 242 | end |
lib/noosfero/api/session.rb
| @@ -36,19 +36,23 @@ module Noosfero | @@ -36,19 +36,23 @@ module Noosfero | ||
| 36 | requires :password, type: String, desc: _("Password") | 36 | requires :password, type: String, desc: _("Password") |
| 37 | end | 37 | end |
| 38 | post "/register" do | 38 | post "/register" do |
| 39 | + binding.pry | ||
| 39 | unique_attributes! User, [:email, :login] | 40 | unique_attributes! User, [:email, :login] |
| 40 | attrs = attributes_for_keys [:email, :login, :password] | 41 | attrs = attributes_for_keys [:email, :login, :password] |
| 41 | attrs[:password_confirmation] = attrs[:password] | 42 | attrs[:password_confirmation] = attrs[:password] |
| 42 | 43 | ||
| 43 | - #Commented for stress tests | ||
| 44 | - | ||
| 45 | - # remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) | ||
| 46 | - # private_key = API.NOOSFERO_CONF['api_recaptcha_private_key'] | ||
| 47 | - # api_recaptcha_verify_uri = API.NOOSFERO_CONF['api_recaptcha_verify_uri'] | ||
| 48 | - # captcha_result = verify_recaptcha_v2(remote_ip, params['g-recaptcha-response'], private_key, api_recaptcha_verify_uri) | 44 | + remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) |
| 45 | + private_key = API.NOOSFERO_CONF['api_recaptcha_private_key'] | ||
| 46 | + api_recaptcha_verify_uri = API.NOOSFERO_CONF['api_recaptcha_verify_uri'] | ||
| 47 | + | ||
| 48 | +# "recaptcha_challenge_field" => "03AHJ_VutRW6eOgTKZyK-77J96k121W0fUHIEvThyCPtqG2FUPBWzidBOqptzk0poh_UkMNPxAd_m0CqUz1Dip-6uV_zlwlviaXXvymwCFXPaWuvvyUfZ3LvZy6M1CoPfbhOQZjTkf_VNjlVnCRuuJXmGy4MhhuJ8om1J_R2C_oIAfP3KbpmlqLXU5nLlE7WpW-h-OhRTQzupTo9UL-4-ZDRk1bMkCSEJnwYUomOboqFBEpJBv0iaOCaSnu9_UKObmWmpbQZSHxYK7", | ||
| 49 | +# "recaptcha_response_field" => "1221" | ||
| 50 | + | ||
| 51 | + #captcha_result = verify_recaptcha_v2(remote_ip, params['g-recaptcha-response'], private_key, api_recaptcha_verify_uri) | ||
| 52 | + captcha_result = verify_recaptcha_v1(remote_ip, params['recaptcha_response_field'], private_key, params['recaptcha_challenge_field'], api_recaptcha_verify_uri) | ||
| 53 | + binding.pry | ||
| 49 | user = User.new(attrs) | 54 | user = User.new(attrs) |
| 50 | -# if captcha_result["success"] and user.save | ||
| 51 | - if user.save | 55 | + if captcha_result["success"] and user.save |
| 52 | user.activate | 56 | user.activate |
| 53 | user.generate_private_token! | 57 | user.generate_private_token! |
| 54 | present user, :with => Entities::UserLogin | 58 | present user, :with => Entities::UserLogin |