Don't set whitelist captcha using session variable

This commit is contained in:
Kyle Drake 2017-02-02 11:33:02 -08:00
parent ad22cc519f
commit 0d9c366555

View file

@ -1,6 +1,5 @@
def new_recaptcha_valid? def new_recaptcha_valid?
return true if session[:captcha_valid] == true return true if ENV['RACK_ENV'] == 'test' || ENV['TRAVIS']
return session[:captcha_valid] = true if ENV['RACK_ENV'] == 'test' || ENV['TRAVIS']
return false unless params[:'g-recaptcha-response'] return false unless params[:'g-recaptcha-response']
resp = Net::HTTP.get URI( resp = Net::HTTP.get URI(
'https://www.google.com/recaptcha/api/siteverify?'+ 'https://www.google.com/recaptcha/api/siteverify?'+
@ -11,7 +10,6 @@ def new_recaptcha_valid?
) )
if JSON.parse(resp)['success'] == true if JSON.parse(resp)['success'] == true
session[:captcha_valid] = true
true true
else else
false false
@ -32,9 +30,7 @@ post '/create_validate_all' do
site = Site.new fields site = Site.new fields
if site.valid? if site.valid?
return [].to_json if education_whitelisted? return [].to_json if education_whitelisted? || params[:'g-recaptcha-response']
return [].to_json if new_recaptcha_valid?
return [['captcha', 'Please complete the captcha.']].to_json return [['captcha', 'Please complete the captcha.']].to_json
end end
@ -86,14 +82,13 @@ post '/create' do
if education_whitelisted? if education_whitelisted?
@site.email_confirmed = true @site.email_confirmed = true
else else
new_recaptcha_valid? if !new_recaptcha_valid?
if session[:captcha_valid] != true
flash[:error] = 'The captcha was not valid, please try again.' flash[:error] = 'The captcha was not valid, please try again.'
return {result: 'error'}.to_json return {result: 'error'}.to_json
end end
if !@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.' flash[:error] = 'Your IP address has created too many sites, please try again later or contact support.'
return {result: 'error'}.to_json return {result: 'error'}.to_json
end end
@ -106,8 +101,6 @@ post '/create' do
@site.email_confirmed = true if self.class.development? @site.email_confirmed = true if self.class.development?
@site.save @site.save
session[:captcha_valid] = nil
unless education_whitelisted? unless education_whitelisted?
@site.send_email( @site.send_email(
subject: "[Neocities] Welcome to Neocities!", subject: "[Neocities] Welcome to Neocities!",