Add ability to set hCaptcha either on registration form or on e-mail validation

Upshot of CAPTCHA on e-mail validation is it does not need to break the in-band
registration API.
This commit is contained in:
Claire
2022-01-25 22:37:12 +01:00
parent a9269f8786
commit 0fb907441c
9 changed files with 91 additions and 10 deletions

View File

@@ -15,17 +15,21 @@ module CaptchaConcern
end
def captcha_enabled?
captcha_available? && Setting.captcha_enabled
captcha_available? && Setting.captcha_mode == captcha_context
end
def captcha_recently_passed?
session[:captcha_passed_at].present? && session[:captcha_passed_at] >= CAPTCHA_TIMEOUT.ago
end
def captcha_user_bypass?
current_user.present? || (@invite.present? && @invite.valid_for_use? && !@invite.max_uses.nil?)
end
def captcha_required?
return false if ENV['OMNIAUTH_ONLY'] == 'true'
return false unless Setting.registrations_mode != 'none' || @invite&.valid_for_use?
captcha_enabled? && !current_user && !(@invite.present? && @invite.valid_for_use? && !@invite.max_uses.nil?) && !captcha_recently_passed?
captcha_enabled? && !captcha_user_bypass? && !captcha_recently_passed?
end
def clear_captcha!
@@ -65,4 +69,8 @@ module CaptchaConcern
hcaptcha_tags
end
def captcha_context
'registration-form'
end
end