summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-06-09 12:28:47 -0700
committerStan Hu <stanhu@gmail.com>2017-06-09 22:28:28 -0700
commitb3b754fd86ad10c2bd396b4d5b21877a6a44b159 (patch)
treeb83a03e18b85434208b7a5e635402002369c825d
parentb134f950d70bdb73bc76e9a9091c0a50a6b8b8cd (diff)
downloadgitlab-ce-sh-init-recaptcha.tar.gz
Load reCAPTCHA config at init time and when application settings changesh-init-recaptcha
Closes #33532
-rw-r--r--app/controllers/concerns/spammable_actions.rb2
-rw-r--r--app/controllers/registrations_controller.rb2
-rw-r--r--app/controllers/sessions_controller.rb5
-rw-r--r--app/models/application_setting.rb1
-rw-r--r--config/initializers/recaptcha.rb1
-rw-r--r--lib/gitlab/recaptcha.rb12
6 files changed, 12 insertions, 11 deletions
diff --git a/app/controllers/concerns/spammable_actions.rb b/app/controllers/concerns/spammable_actions.rb
index d0a692070d9..004872ff4ca 100644
--- a/app/controllers/concerns/spammable_actions.rb
+++ b/app/controllers/concerns/spammable_actions.rb
@@ -35,7 +35,7 @@ module SpammableActions
default_params = { request: request }
recaptcha_check = params[:recaptcha_verification] &&
- Gitlab::Recaptcha.load_configurations! &&
+ Gitlab::Recaptcha.enabled? &&
verify_recaptcha
return default_params unless recaptcha_check
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 1bc6520370a..1e46e25b6fb 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -13,7 +13,7 @@ class RegistrationsController < Devise::RegistrationsController
params[resource_name] = params.delete(:"new_#{resource_name}")
end
- if !Gitlab::Recaptcha.load_configurations! || verify_recaptcha
+ if !Gitlab::Recaptcha.enabled? || verify_recaptcha
super
else
flash[:alert] = 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index d7c702b94f8..345e411f30b 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -11,7 +11,6 @@ class SessionsController < Devise::SessionsController
prepend_before_action :store_redirect_path, only: [:new]
before_action :auto_sign_in_with_provider, only: [:new]
- before_action :load_recaptcha
def new
set_minimum_password_length
@@ -137,10 +136,6 @@ class SessionsController < Devise::SessionsController
Users::ActivityService.new(user, 'login').execute
end
- def load_recaptcha
- Gitlab::Recaptcha.load_configurations!
- end
-
def authentication_method
if user_params[:otp_attempt]
"two-factor"
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 2192f76499d..ea01c48a7f5 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -171,6 +171,7 @@ class ApplicationSetting < ActiveRecord::Base
after_commit do
Rails.cache.write(CACHE_KEY, self)
+ Gitlab::Recaptcha.load_configurations!
end
def self.current
diff --git a/config/initializers/recaptcha.rb b/config/initializers/recaptcha.rb
new file mode 100644
index 00000000000..4dc6e21217a
--- /dev/null
+++ b/config/initializers/recaptcha.rb
@@ -0,0 +1 @@
+Gitlab::Recaptcha.load_configurations!
diff --git a/lib/gitlab/recaptcha.rb b/lib/gitlab/recaptcha.rb
index 4bc76ea033f..97c61df8b94 100644
--- a/lib/gitlab/recaptcha.rb
+++ b/lib/gitlab/recaptcha.rb
@@ -1,10 +1,10 @@
module Gitlab
module Recaptcha
def self.load_configurations!
- if current_application_settings.recaptcha_enabled
+ if self.current_settings.recaptcha_enabled
::Recaptcha.configure do |config|
- config.public_key = current_application_settings.recaptcha_site_key
- config.private_key = current_application_settings.recaptcha_private_key
+ config.public_key = self.current_settings.recaptcha_site_key
+ config.private_key = self.current_settings.recaptcha_private_key
end
true
@@ -12,7 +12,11 @@ module Gitlab
end
def self.enabled?
- current_application_settings.recaptcha_enabled
+ self.current_settings.recaptcha_enabled
+ end
+
+ def self.current_settings
+ Class.new.extend(CurrentSettings).current_application_settings
end
end
end