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
def create
if !APP_CONFIG.dig(:hcaptcha, :enabled) || verify_hcaptcha(model: resource)
if captcha_valid?
super
else
respond_with_navigational(resource){ redirect_to new_user_registration_path }
@ -14,4 +14,13 @@ class User::RegistrationsController < Devise::RegistrationsController
yield resource if block_given?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
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

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)
Hcaptcha.configure do |config|
config.site_key = APP_CONFIG.dig(:hcaptcha, :site_key)
config.secret_key = APP_CONFIG.dig(:hcaptcha, :secret_key)
end
return unless APP_CONFIG.dig(:hcaptcha, :enabled)
Hcaptcha.configure do |config|
config.site_key = APP_CONFIG.dig(:hcaptcha, :site_key)
config.secret_key = APP_CONFIG.dig(:hcaptcha, :secret_key)
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