mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
switch to captcha v2 api
This commit is contained in:
parent
7b0c26c1c2
commit
dae2466487
9 changed files with 29 additions and 45 deletions
1
Gemfile
1
Gemfile
|
@ -8,7 +8,6 @@ gem 'bcrypt'
|
||||||
gem 'sinatra-flash', require: 'sinatra/flash'
|
gem 'sinatra-flash', require: 'sinatra/flash'
|
||||||
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
|
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
|
||||||
gem 'puma', require: nil
|
gem 'puma', require: nil
|
||||||
gem 'rack-recaptcha', require: 'rack/recaptcha'
|
|
||||||
gem 'rmagick', require: nil
|
gem 'rmagick', require: nil
|
||||||
gem 'sidekiq', '~> 4.1.2'
|
gem 'sidekiq', '~> 4.1.2'
|
||||||
gem 'mail'
|
gem 'mail'
|
||||||
|
|
|
@ -180,8 +180,6 @@ GEM
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
rack-protection (2.0.0)
|
rack-protection (2.0.0)
|
||||||
rack
|
rack
|
||||||
rack-recaptcha (0.6.6)
|
|
||||||
json
|
|
||||||
rack-test (0.8.2)
|
rack-test (0.8.2)
|
||||||
rack (>= 1.0, < 3)
|
rack (>= 1.0, < 3)
|
||||||
rack_session_access (0.1.1)
|
rack_session_access (0.1.1)
|
||||||
|
@ -331,7 +329,6 @@ DEPENDENCIES
|
||||||
pry-byebug
|
pry-byebug
|
||||||
puma
|
puma
|
||||||
rack-cache
|
rack-cache
|
||||||
rack-recaptcha
|
|
||||||
rack-test
|
rack-test
|
||||||
rack_session_access
|
rack_session_access
|
||||||
rake
|
rake
|
||||||
|
@ -363,4 +360,4 @@ DEPENDENCIES
|
||||||
zipruby
|
zipruby
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.16.0
|
1.16.1
|
||||||
|
|
2
app.rb
2
app.rb
|
@ -9,9 +9,7 @@ use Rack::Session::Cookie, key: 'neocities',
|
||||||
same_site: :lax,
|
same_site: :lax,
|
||||||
secure: ENV['RACK_ENV'] == 'production'
|
secure: ENV['RACK_ENV'] == 'production'
|
||||||
|
|
||||||
use Rack::Recaptcha, public_key: $config['recaptcha_public_key'], private_key: $config['recaptcha_private_key']
|
|
||||||
use Rack::TempfileReaper
|
use Rack::TempfileReaper
|
||||||
helpers Rack::Recaptcha::Helpers
|
|
||||||
|
|
||||||
helpers do
|
helpers do
|
||||||
def site_change_file_display_class(filename)
|
def site_change_file_display_class(filename)
|
||||||
|
|
|
@ -40,7 +40,7 @@ post '/contact' do
|
||||||
no_footer: true
|
no_footer: true
|
||||||
})
|
})
|
||||||
|
|
||||||
flash[:success] = 'Your contact has been sent.'
|
flash[:success] = 'Your contact message has been sent.'
|
||||||
redirect '/'
|
redirect '/'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,3 @@
|
||||||
def new_recaptcha_valid?
|
|
||||||
return true if ENV['RACK_ENV'] == 'test' || ENV['TRAVIS']
|
|
||||||
return false unless params[:'g-recaptcha-response']
|
|
||||||
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
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
CREATE_MATCH_REGEX = /^username$|^password$|^email$|^new_tags_string$|^is_education$/
|
CREATE_MATCH_REGEX = /^username$|^password$|^email$|^new_tags_string$|^is_education$/
|
||||||
|
|
||||||
def education_whitelisted?
|
def education_whitelisted?
|
||||||
|
@ -82,7 +64,7 @@ post '/create' do
|
||||||
if education_whitelisted?
|
if education_whitelisted?
|
||||||
@site.email_confirmed = true
|
@site.email_confirmed = true
|
||||||
else
|
else
|
||||||
if !new_recaptcha_valid?
|
if !recaptcha_valid?
|
||||||
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
|
||||||
|
|
|
@ -122,3 +122,21 @@ end
|
||||||
def flash_display(opts={})
|
def flash_display(opts={})
|
||||||
erb :'_flash', layout: false, locals: {opts: opts}
|
erb :'_flash', layout: false, locals: {opts: opts}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def recaptcha_valid?
|
||||||
|
return true if ENV['RACK_ENV'] == 'test' || ENV['TRAVIS']
|
||||||
|
return false unless params[:'g-recaptcha-response']
|
||||||
|
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
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
<script>
|
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||||
var RecaptchaOptions = {
|
|
||||||
theme : 'clean'
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="header-Outro">
|
<div class="header-Outro">
|
||||||
<div class="row content single-Col">
|
<div class="row content single-Col">
|
||||||
|
@ -227,8 +223,9 @@
|
||||||
<textarea name="body" id="your_comments" class="col-75" rows="10"><%= params[:body] %></textarea>
|
<textarea name="body" id="your_comments" class="col-75" rows="10"><%= params[:body] %></textarea>
|
||||||
|
|
||||||
<label>Fill out the captcha so we know you’re not a robot:</label>
|
<label>Fill out the captcha so we know you’re not a robot:</label>
|
||||||
<div class="recaptcha">
|
<div id="captcha-input" class="g-recaptcha"
|
||||||
<%== recaptcha_tag :challenge, ssl: request.ssl? %>
|
data-sitekey="<%= $config['recaptcha_public_key'] %>"
|
||||||
|
data-theme="light" data-placement="left" data-trigger="manual">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input class="btn-Action" type="submit" value="Send">
|
<input class="btn-Action" type="submit" value="Send">
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
<script>
|
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||||
var RecaptchaOptions = {
|
|
||||||
theme : 'clean'
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="header-Outro">
|
<div class="header-Outro">
|
||||||
<div class="row content single-Col">
|
<div class="row content single-Col">
|
||||||
|
@ -51,8 +47,9 @@
|
||||||
<textarea name="body" id="your_comments" class="col-80" rows="10"><%= params[:body] %></textarea>
|
<textarea name="body" id="your_comments" class="col-80" rows="10"><%= params[:body] %></textarea>
|
||||||
|
|
||||||
<label>Fill out the captcha so we know you’re not a robot:</label>
|
<label>Fill out the captcha so we know you’re not a robot:</label>
|
||||||
<div class="recaptcha">
|
<div id="captcha-input" class="g-recaptcha"
|
||||||
<%== recaptcha_tag :challenge, ssl: request.ssl? %>
|
data-sitekey="<%= $config['recaptcha_public_key'] %>"
|
||||||
|
data-theme="light" data-placement="left" data-trigger="manual">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input class="btn-Action" type="submit" value="Send">
|
<input class="btn-Action" type="submit" value="Send">
|
||||||
|
|
|
@ -38,10 +38,6 @@
|
||||||
<script type="text/javascript" src="/js/html5.min.js"></script>
|
<script type="text/javascript" src="/js/html5.min.js"></script>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
<script>
|
|
||||||
var RecaptchaOptions = {theme: 'clean'}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="/js/jquery-1.11.0.min.js"></script>
|
<script src="/js/jquery-1.11.0.min.js"></script>
|
||||||
|
|
||||||
<script src="/js/highlight.pack.js"></script>
|
<script src="/js/highlight.pack.js"></script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue