fixes for hcaptcha, add to dmca form

This commit is contained in:
Kyle Drake 2020-11-26 01:45:23 -06:00
parent 79cdd06b19
commit 2821f513f1
9 changed files with 32 additions and 25 deletions

View file

@ -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
View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -163,8 +163,3 @@ $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

View file

@ -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 youre 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>

View file

@ -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 youre 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>

View file

@ -13,7 +13,3 @@
<p>
1-503-395-0010
</p>
<h3>Fax</h3>
<p>
1-541-238-9273
</p>