From acb23ef2bcefca955b0946d7de324eb450f50d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Vigui=C3=A9?= Date: Fri, 8 May 2020 13:19:05 +0200 Subject: [PATCH] requested changes & style cleanup --- app/controllers/api/v1/accounts_controller.rb | 15 +++++++++------ app/controllers/auth/registrations_controller.rb | 6 +++--- app/helpers/application_helper.rb | 1 - config/initializers/content_security_policy.rb | 2 +- config/locales/en.yml | 2 -- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 78b7fdb0d8..3f75fabad2 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -21,14 +21,17 @@ class Api::V1::AccountsController < Api::BaseController end def create - not_found -# token = AppSignUpService.new.call(doorkeeper_token.application, account_params) -# response = Doorkeeper::OAuth::TokenResponse.new(token) + if ENV['HCAPTCHA_ENABLED'] == 'true' + not_found + else + token = AppSignUpService.new.call(doorkeeper_token.application, account_params) + response = Doorkeeper::OAuth::TokenResponse.new(token) -# headers.merge!(response.headers) + headers.merge!(response.headers) -# self.response_body = Oj.dump(response.body) -# self.status = response.status + self.response_body = Oj.dump(response.body) + self.status = response.status + end end def follow diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 563c3cdb99..bb621adf23 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -96,10 +96,10 @@ class Auth::RegistrationsController < Devise::RegistrationsController def check_captcha if ENV['HCAPTCHA_ENABLED'] == 'true' && !verify_hcaptcha - self.resource = resource_class.new sign_up_params + build_resource(sign_up_params) resource.validate - flash[:alert] = Hcaptcha::Helpers.to_error_message(:verification_failed) - respond_with_navigational(resource) { render :new } + resource.errors.add(:base, flash.delete(:hcaptcha_error)) + respond_with resource end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d4e94fa9e3..40f914f1e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -148,5 +148,4 @@ module ApplicationHelper json = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(state_params), serializer: InitialStateSerializer).to_json content_tag(:script, json_escape(json).html_safe, id: 'initial-state', type: 'application/json') end - end diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 1ea29783a8..a7a55dbf8c 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -16,7 +16,7 @@ if Rails.env.production? attachments_host = nil end - hcaptcha_hosts = ["https://hcaptcha.com", "https://*.hcaptcha.com"] + hcaptcha_hosts = ENV['HCAPTCHA_ENABLED'] == 'true' ? ["https://hcaptcha.com", "https://*.hcaptcha.com"] : nil data_hosts << attachments_host unless attachments_host.nil? diff --git a/config/locales/en.yml b/config/locales/en.yml index 432d8e910f..61ce1aceb8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -543,8 +543,6 @@ en: deletion: desc_html: Allow anyone to delete their account title: Open account deletion - errors: - captcha_fail: Captcha verification failed min_invite_role: disabled: No one title: Allow invitations by