Commit 29917cb10092898f7c1df816626b4c87d996f263
Exists in
staging
and in
4 other branches
Merge branch 'api' into production
Showing
5 changed files
with
58 additions
and
10 deletions
Show diff stats
lib/noosfero/api/api.rb
... | ... | @@ -9,7 +9,7 @@ module Noosfero |
9 | 9 | |
10 | 10 | logger = Logger.new(File.join(Rails.root, 'log', "#{ENV['RAILS_ENV'] || 'production'}_api.log")) |
11 | 11 | logger.formatter = GrapeLogging::Formatters::Default.new |
12 | - use RequestLogger, { logger: logger } | |
12 | + use GrapeLogging::Middleware::RequestLogger, { logger: logger } | |
13 | 13 | |
14 | 14 | rescue_from :all do |e| |
15 | 15 | logger.error e |
... | ... | @@ -45,6 +45,7 @@ module Noosfero |
45 | 45 | mount V1::Enterprises |
46 | 46 | mount V1::Categories |
47 | 47 | mount V1::Tasks |
48 | + mount V1::Environments | |
48 | 49 | mount Session |
49 | 50 | |
50 | 51 | # hook point which allow plugins to add Grape::API extensions to API::API | ... | ... |
lib/noosfero/api/entities.rb
lib/noosfero/api/helpers.rb
... | ... | @@ -114,6 +114,7 @@ module Noosfero |
114 | 114 | end |
115 | 115 | |
116 | 116 | def verify_recaptcha_v2(remote_ip, g_recaptcha_response, private_key, api_recaptcha_verify_uri) |
117 | + binding.pry | |
117 | 118 | verify_hash = { |
118 | 119 | "secret" => private_key, |
119 | 120 | "remoteip" => remote_ip, |
... | ... | @@ -216,6 +217,26 @@ module Noosfero |
216 | 217 | begin_period..end_period |
217 | 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 | 240 | end |
220 | 241 | end |
221 | 242 | end | ... | ... |
lib/noosfero/api/session.rb
... | ... | @@ -36,19 +36,23 @@ module Noosfero |
36 | 36 | requires :password, type: String, desc: _("Password") |
37 | 37 | end |
38 | 38 | post "/register" do |
39 | + binding.pry | |
39 | 40 | unique_attributes! User, [:email, :login] |
40 | - attrs = attributes_for_keys [:email, :login, :password] | |
41 | + attrs = attributes_for_keys [:email, :login, :password] + environment.signup_person_fields | |
41 | 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 | 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 | 56 | user.activate |
53 | 57 | user.generate_private_token! |
54 | 58 | present user, :with => Entities::UserLogin | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +module Noosfero | |
2 | + module API | |
3 | + module V1 | |
4 | + class Environments < Grape::API | |
5 | + | |
6 | + resource :environment do | |
7 | + | |
8 | + desc "Return the person information" | |
9 | + get '/signup_person_fields' do | |
10 | + present environment.signup_person_fields | |
11 | + end | |
12 | + | |
13 | + end | |
14 | + | |
15 | + end | |
16 | + end | |
17 | + end | |
18 | +end | ... | ... |