Address @nilsding's review comments

This commit is contained in:
Dominik M. Kwiatek 2020-05-23 15:49:03 +01:00
parent 29f6313c9a
commit a92dd54be3
4 changed files with 30 additions and 15 deletions

View File

@ -1,6 +1,6 @@
class User::RegistrationsController < Devise::RegistrationsController class User::RegistrationsController < Devise::RegistrationsController
def create def create
if !APP_CONFIG.dig(:hcaptcha, :enabled) || verify_hcaptcha(model: resource) if captcha_valid?
super super
else else
respond_with_navigational(resource){ redirect_to new_user_registration_path } respond_with_navigational(resource){ redirect_to new_user_registration_path }
@ -14,4 +14,13 @@ class User::RegistrationsController < Devise::RegistrationsController
yield resource if block_given? yield resource if block_given?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) } respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end end
private
def captcha_valid?
# If the captcha isn't enabled, treat it as being correct
return true unless APP_CONFIG.dig(:hcaptcha, :enabled)
verify_hcaptcha
end
end end

View File

@ -1,9 +0,0 @@
- if resource.errors.any?
#error-explanation
%h2
= I18n.t('errors.messages.not_saved',
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
%ul
- resource.errors.full_messages.each do |message|
%li= message

View File

@ -1,6 +1,6 @@
if APP_CONFIG.dig(:hcaptcha, :enabled) return unless APP_CONFIG.dig(:hcaptcha, :enabled)
Hcaptcha.configure do |config|
config.site_key = APP_CONFIG.dig(:hcaptcha, :site_key) Hcaptcha.configure do |config|
config.secret_key = APP_CONFIG.dig(:hcaptcha, :secret_key) config.site_key = APP_CONFIG.dig(:hcaptcha, :site_key)
end config.secret_key = APP_CONFIG.dig(:hcaptcha, :secret_key)
end end

View File

@ -0,0 +1,15 @@
require 'rspec'
describe User::RegistrationsController do
before do
# Do nothing
end
after do
# Do nothing
end
describe "#create" do
end
end