Fixed captcha on login screen.#139
Conversation
📝 WalkthroughWalkthroughImplements a reCAPTCHA v3 guard mechanism that prevents form submission until a token is available. Changes include threshold configuration adjustment, a new JavaScript library for token polling, a form alter hook to attach the guard behavior conditionally, and theme preprocessing updates for hidden inputs. Changes
Sequence DiagramsequenceDiagram
participant Client as Client/Browser
participant FormHook as Form Alter Hook
participant JS as JavaScript Behavior
participant reCAPTCHA as reCAPTCHA v3
participant Submit as Form Submission
Client->>FormHook: Form render request
FormHook->>FormHook: Check for recaptcha_v3 captcha
FormHook->>Client: Attach recaptcha_v3_guard library
Client->>JS: Execute guard behavior attach
JS->>JS: Locate token input & form
JS->>JS: Disable all submit buttons
JS->>reCAPTCHA: Poll for token (every 200ms)
alt Token received within 5s
reCAPTCHA-->>JS: Token available
else 5s timeout
JS->>JS: Timeout reached
end
JS->>JS: Enable submit buttons
Client->>Submit: User submits form
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/themes/custom/drevops/drevops.theme`:
- Around line 28-36: The drevops_preprocess_input__hidden function currently
unconditionally sets $variables['modifier_class'] = FALSE which wipes any
existing modifier classes; change it so you only set it to FALSE when the key is
missing or empty (e.g., check isset() or empty() on
$variables['modifier_class']) and otherwise preserve the existing value so
contributed modules' classes remain intact.
| /** | ||
| * Implements hook_preprocess_HOOK() for hidden input templates. | ||
| */ | ||
| function drevops_preprocess_input__hidden(array &$variables): void { | ||
| // Hidden inputs should not have classes as classes are used for presentation. | ||
| // But some contributed modules use classes on hidden inputs and target them | ||
| // with JavaScript, so we need to allow classes if they are already set. | ||
| $variables['modifier_class'] = FALSE; | ||
| } |
There was a problem hiding this comment.
Preserve existing modifier_class values instead of always overwriting (Line 35).
The comment says to allow existing classes, but Line 35 always forces modifier_class to FALSE, which can wipe module-provided modifier classes. Consider only forcing FALSE when no value is present.
🛠️ Suggested fix
function drevops_preprocess_input__hidden(array &$variables): void {
// Hidden inputs should not have classes as classes are used for presentation.
// But some contributed modules use classes on hidden inputs and target them
// with JavaScript, so we need to allow classes if they are already set.
- $variables['modifier_class'] = FALSE;
+ if (empty($variables['modifier_class'])) {
+ $variables['modifier_class'] = FALSE;
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * Implements hook_preprocess_HOOK() for hidden input templates. | |
| */ | |
| function drevops_preprocess_input__hidden(array &$variables): void { | |
| // Hidden inputs should not have classes as classes are used for presentation. | |
| // But some contributed modules use classes on hidden inputs and target them | |
| // with JavaScript, so we need to allow classes if they are already set. | |
| $variables['modifier_class'] = FALSE; | |
| } | |
| /** | |
| * Implements hook_preprocess_HOOK() for hidden input templates. | |
| */ | |
| function drevops_preprocess_input__hidden(array &$variables): void { | |
| // Hidden inputs should not have classes as classes are used for presentation. | |
| // But some contributed modules use classes on hidden inputs and target them | |
| // with JavaScript, so we need to allow classes if they are already set. | |
| if (empty($variables['modifier_class'])) { | |
| $variables['modifier_class'] = FALSE; | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@web/themes/custom/drevops/drevops.theme` around lines 28 - 36, The
drevops_preprocess_input__hidden function currently unconditionally sets
$variables['modifier_class'] = FALSE which wipes any existing modifier classes;
change it so you only set it to FALSE when the key is missing or empty (e.g.,
check isset() or empty() on $variables['modifier_class']) and otherwise preserve
the existing value so contributed modules' classes remain intact.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #139 +/- ##
=======================================
Coverage 0.00% 0.00%
=======================================
Files 2 3 +1
Lines 10 15 +5
=======================================
- Misses 10 15 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Bug Fixes