mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fixes for hcaptcha, add to dmca form
This commit is contained in:
parent
79cdd06b19
commit
2821f513f1
9 changed files with 32 additions and 25 deletions
1
Gemfile
1
Gemfile
|
@ -53,7 +53,6 @@ gem 'activesupport'
|
|||
gem 'facter', require: nil
|
||||
gem 'maxmind-db'
|
||||
gem 'json', '>= 2.3.0'
|
||||
gem 'hcaptcha'
|
||||
|
||||
group :development, :test do
|
||||
gem 'pry'
|
||||
|
|
9
app.rb
9
app.rb
|
@ -11,8 +11,6 @@ use Rack::Session::Cookie, key: 'neocities',
|
|||
|
||||
use Rack::TempfileReaper
|
||||
|
||||
include Hcaptcha::Adapters::ControllerMethods
|
||||
|
||||
helpers do
|
||||
def site_change_file_display_class(filename)
|
||||
return 'html' if filename.match(Site::HTML_REGEX)
|
||||
|
@ -24,7 +22,12 @@ helpers do
|
|||
%{<input name="csrf_token" type="hidden" value="#{csrf_token}">}
|
||||
end
|
||||
|
||||
include Hcaptcha::Adapters::ViewMethods
|
||||
def hcaptcha_input
|
||||
%{
|
||||
<script src="https://hcaptcha.com/1/api.js" async defer></script>
|
||||
<div class="h-captcha" data-sitekey="#{$config['hcaptcha_site_key']}"></div>
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
set :protection, :frame_options => "DENY"
|
||||
|
|
|
@ -9,7 +9,7 @@ post '/contact' do
|
|||
@errors << 'Please fill out all fields'
|
||||
end
|
||||
|
||||
unless verify_hcaptcha
|
||||
unless hcaptcha_valid?
|
||||
@errors << 'Captcha was not filled out (or was filled out incorrectly)'
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ post '/dmca/contact' do
|
|||
@errors << 'Please fill out all fields'
|
||||
end
|
||||
|
||||
if !recaptcha_valid?
|
||||
if !hcaptcha_valid?
|
||||
@errors << 'Captcha was not filled out (or was filled out incorrectly)'
|
||||
end
|
||||
|
||||
|
|
|
@ -135,3 +135,24 @@ def recaptcha_valid?
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
def hcaptcha_valid?
|
||||
return true if ENV['RACK_ENV'] == 'test' || ENV['TRAVIS']
|
||||
return false unless params[:'h-captcha-response']
|
||||
|
||||
resp = Net::HTTP.get URI(
|
||||
'https://hcaptcha.com/siteverify?'+
|
||||
Rack::Utils.build_query(
|
||||
secret: $config['hcaptcha_secret_key'],
|
||||
response: params[:'h-captcha-response']
|
||||
)
|
||||
)
|
||||
|
||||
resp = JSON.parse resp
|
||||
|
||||
if resp['success'] == true
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
|
@ -162,9 +162,4 @@ $gandi = Gandi::Session.new $config['gandi_api_key'], gandi_opts
|
|||
|
||||
$image_optim = ImageOptim.new pngout: false, svgo: false
|
||||
|
||||
Money.locale_backend = nil
|
||||
|
||||
Hcaptcha.configure do |config|
|
||||
config.site_key = $config['hcaptcha_site_key']
|
||||
config.secret_key = $config['hcaptcha_secret_key']
|
||||
end
|
||||
Money.locale_backend = nil
|
|
@ -1,5 +1,3 @@
|
|||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||
|
||||
<div class="header-Outro">
|
||||
<div class="row content single-Col">
|
||||
<h1>Contact Us</h1>
|
||||
|
@ -253,9 +251,7 @@
|
|||
<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>
|
||||
<div id="captcha-input" class="g-recaptcha">
|
||||
<%== hcaptcha_tags %>
|
||||
</div>
|
||||
<%== hcaptcha_input %>
|
||||
|
||||
<input class="btn-Action" type="submit" value="Send">
|
||||
</fieldset>
|
||||
|
|
|
@ -47,10 +47,7 @@
|
|||
<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>
|
||||
<div id="captcha-input" class="g-recaptcha"
|
||||
data-sitekey="<%= $config['recaptcha_public_key'] %>"
|
||||
data-theme="light" data-placement="left" data-trigger="manual">
|
||||
</div>
|
||||
<%== hcaptcha_input %>
|
||||
|
||||
<input class="btn-Action" type="submit" value="Send">
|
||||
</fieldset>
|
||||
|
|
|
@ -13,7 +13,3 @@
|
|||
<p>
|
||||
1-503-395-0010
|
||||
</p>
|
||||
<h3>Fax</h3>
|
||||
<p>
|
||||
1-541-238-9273
|
||||
</p>
|
||||
|
|
Loading…
Add table
Reference in a new issue