Skip to content

Commit e059dcf

Browse files
pmusarajpento
authored andcommitted
FIX: Hcaptcha plugin was incompatible with login-required sites (#34181)
1 parent a6af10f commit e059dcf

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

plugins/discourse-hcaptcha/app/controllers/discourse_hcaptcha/hcaptcha_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class HcaptchaController < ::ApplicationController
55
requires_plugin DiscourseHcaptcha::PLUGIN_NAME
66

77
before_action :ensure_config
8+
skip_before_action :redirect_to_login_if_required
9+
810
TOKEN_TTL = 2.minutes
911
protect_from_forgery except: [:create]
1012

plugins/discourse-hcaptcha/spec/lib/discourse_h_captcha/create_users_controller_patch_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@
5656
post "/u.json", params: user_params
5757
expect(JSON.parse(response.body)["success"]).to be(true)
5858
end
59+
60+
context "when site is login-required" do
61+
before { SiteSetting.login_required = true }
62+
63+
it "succeeds in registration" do
64+
post "/hcaptcha/create.json", params: { token: "token-from-hCaptcha" }
65+
post "/u.json", params: user_params
66+
expect(JSON.parse(response.body)["success"]).to be(true)
67+
end
68+
end
5969
end
6070

6171
context "when h_captcha is disabled" do

0 commit comments

Comments
 (0)