diff --git a/app/create.rb b/app/create.rb index f5f4ac17..87451727 100644 --- a/app/create.rb +++ b/app/create.rb @@ -1,9 +1,32 @@ +def new_recaptcha_valid? + return session[:captcha_valid] = true if ENV['RACK_ENV'] == 'test' + resp = Net::HTTP.get URI( + 'https://www.google.com/recaptcha/api/siteverify?'+ + Rack::Utils.build_query( + secret: $config['recaptcha_private_key'], + response: params[:'g-recaptcha-response'] + ) + ) + + if JSON.parse(resp)['success'] == true + session[:captcha_valid] = true + true + else + false + end +end + post '/create_validate_all' do content_type :json fields = params.select {|p| p.match /^username$|^password$|^email$|^new_tags_string$/} site = Site.new fields - return [].to_json if site.valid? + + if site.valid? + return [].to_json if new_recaptcha_valid? + return [['captcha', 'Please complete the captcha.']].to_json + end + site.errors.collect {|e| [e.first, e.last.first]}.to_json end @@ -39,25 +62,20 @@ post '/create' do ip: request.ip ) - black_box_answered = BlackBox.valid? params[:blackbox_answer], request.ip - question_answered_correctly = params[:question_answer] == session[:question_answer] - - if !question_answered_correctly - question_first_number, question_last_number = generate_question - return { - result: 'bad_answer', - question_first_number: question_first_number, - question_last_number: question_last_number - }.to_json + if session[:captcha_valid] != true + flash[:error] = 'The captcha was not valid, please try again.' + return {result: 'error'}.to_json end - if !black_box_answered || !@site.valid? || Site.ip_create_limit?(request.ip) + if !@site.valid? || Site.ip_create_limit?(request.ip) flash[:error] = 'There was an unknown error, please try again.' return {result: 'error'}.to_json end @site.save + session[:captcha_valid] = nil + EmailWorker.perform_async({ from: 'web@neocities.org', reply_to: 'contact@neocities.org', diff --git a/tests/acceptance/signup_tests.rb b/tests/acceptance/signup_tests.rb index 3ab21c5d..59566676 100644 --- a/tests/acceptance/signup_tests.rb +++ b/tests/acceptance/signup_tests.rb @@ -8,7 +8,6 @@ describe 'signup' do fill_in 'username', with: @site[:username] fill_in 'password', with: @site[:password] fill_in 'email', with: @site[:email] - fill_in 'question_answer', with: 2 end def click_signup_button diff --git a/views/index.erb b/views/index.erb index 7e223fb4..88bc48c6 100644 --- a/views/index.erb +++ b/views/index.erb @@ -37,6 +37,7 @@ +
@@ -116,9 +117,9 @@- Neocities is a community of <%= @sites_count.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %> sites that are bringing back the lost individual creativity of the web by giving everyone in the world a free web site. Anyone can make a site—only your imagination is required. Join us! + Neocities is a community of <%= @sites_count.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %> sites that are bringing back the lost individual creativity of the web by giving everyone in the world free web space. Anyone can make a site—only your imagination is required. Join us!