Skip to content

feat: check-in feature integrates Turnstile security check - #2571

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/check-in-security-check
Jan 3, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/check-in-security-check

Conversation

@seefs001

@seefs001 seefs001 commented Jan 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added Turnstile verification modal to the check-in process. When verification is required, a security widget will appear to complete the check-in action.
  • Chores

    • Removed debug logging statements.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 3, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a Turnstile-based security verification layer for check-in functionality, adding middleware validation on the backend and a conditional modal-based security challenge flow on the frontend that triggers when check-in attempts fail.

Changes

Cohort / File(s) Summary
Backend Middleware
router/api-router.go
Adds TurnstileCheck middleware to POST /checkin route, introducing an additional validation layer before the DoCheckin handler executes.
Frontend Components
web/src/components/settings/PersonalSetting.jsx, web/src/components/settings/personal/cards/CheckinCalendar.jsx
PersonalSetting passes turnstileEnabled and turnstileSiteKey props to CheckinCalendar. CheckinCalendar now accepts these props and implements a Turnstile modal with conditional triggering logic, token-aware API calls, and widget refresh on expiration. Component signature expanded.
Frontend Services
web/src/services/secureVerification.js
Disables debug console.log statements via commenting; no logic changes.

Sequence Diagram

sequenceDiagram
    participant UI as CheckinCalendar UI
    participant API as Backend API
    participant Turnstile as Turnstile Widget
    participant Service as Verification Service

    UI->>API: POST /api/user/checkin (without token)
    API->>API: TurnstileCheck Middleware
    API-->>UI: Error (requires Turnstile)
    
    alt Turnstile Required
        UI->>UI: Show Turnstile Modal
        UI->>Turnstile: Initialize Widget
        Turnstile-->>UI: Challenge Complete (token)
        UI->>API: POST /api/user/checkin?turnstile=token
    else User Cancels
        UI->>UI: Close Modal & Reset Widget
    end
    
    API->>Service: Verify Token & Process Check-in
    Service-->>API: Success/Failure
    
    alt Success
        API-->>UI: Check-in Confirmed
        UI->>UI: Close Modal, Show Success
    else Failure with Turnstile
        API-->>UI: Refresh Required
        UI->>UI: Reset Widget Key (Reinitialize)
    else Other Error
        API-->>UI: Error Message
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 A turnstile spins, security clear,
When check-ins need a challenge near!
With widgets and tokens, the flow's complete,
Backend and frontend now securely greet!
Hop forth with verification in sight! 🎪

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding Turnstile security integration to the check-in feature across backend routing, frontend components, and state management.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
web/src/services/secureVerification.js (1)

45-71: Inconsistent debug logging cleanup.

Lines 45-50 comment out debug logs, but lines 59-71 still contain active console.log statements that expose calculation details (success status, enabled flags). Consider commenting out or removing these as well for consistency.

🔎 Proposed fix
-      console.log('has2FA calculation:', {
-        success: twoFAResponse.data?.success,
-        dataExists: !!twoFAResponse.data?.data,
-        enabled: twoFAResponse.data?.data?.enabled,
-        result: has2FA,
-      });
-
-      console.log('hasPasskey calculation:', {
-        success: passkeyResponse.data?.success,
-        dataExists: !!passkeyResponse.data?.data,
-        enabled: passkeyResponse.data?.data?.enabled,
-        result: hasPasskey,
-      });
+      // console.log('has2FA calculation:', {
+      //   success: twoFAResponse.data?.success,
+      //   dataExists: !!twoFAResponse.data?.data,
+      //   enabled: twoFAResponse.data?.data?.enabled,
+      //   result: has2FA,
+      // });
+
+      // console.log('hasPasskey calculation:', {
+      //   success: passkeyResponse.data?.success,
+      //   dataExists: !!passkeyResponse.data?.data,
+      //   enabled: passkeyResponse.data?.data?.enabled,
+      //   result: hasPasskey,
+      // });
web/src/components/settings/personal/cards/CheckinCalendar.jsx (2)

116-127: Consider refining shouldTriggerTurnstile logic.

The current implementation returns true for any non-string message when Turnstile is enabled (line 125), which may incorrectly trigger the Turnstile modal for unrelated errors (e.g., network failures returning undefined). Consider being more explicit:

🔎 Proposed fix
  const shouldTriggerTurnstile = (message) => {
    if (!turnstileEnabled) return false;
-   if (typeof message !== 'string') return true;
-   return message.includes('Turnstile');
+   if (typeof message !== 'string') return false;
+   return message.includes('Turnstile') || message.includes('turnstile');
  };

217-226: Modal title should be internationalized.

The modal title "Security Check" is hardcoded in English. Use the translation function for consistency with the rest of the component.

🔎 Proposed fix
      <Modal
-       title='Security Check'
+       title={t('安全验证')}
        visible={turnstileModalVisible}
        footer={null}
        centered
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43c671b and c33ac97.

📒 Files selected for processing (4)
  • router/api-router.go
  • web/src/components/settings/PersonalSetting.jsx
  • web/src/components/settings/personal/cards/CheckinCalendar.jsx
  • web/src/services/secureVerification.js
🧰 Additional context used
🧬 Code graph analysis (3)
router/api-router.go (2)
middleware/turnstile-check.go (1)
  • TurnstileCheck (17-81)
controller/checkin.go (1)
  • DoCheckin (47-72)
web/src/components/settings/personal/cards/CheckinCalendar.jsx (1)
web/src/components/settings/PersonalSetting.jsx (2)
  • turnstileEnabled (67-67)
  • turnstileSiteKey (68-68)
web/src/components/settings/PersonalSetting.jsx (2)
web/src/components/settings/personal/cards/CheckinCalendar.jsx (1)
  • CheckinCalendar (42-382)
web/src/components/auth/LoginForm.jsx (3)
  • status (105-108)
  • turnstileEnabled (71-71)
  • turnstileSiteKey (72-72)
🔇 Additional comments (4)
router/api-router.go (1)

99-99: LGTM!

The TurnstileCheck middleware integration follows the established pattern used elsewhere (registration, login, email verification). The middleware correctly gates the check-in endpoint and leverages session-based caching to avoid repeated verification.

web/src/components/settings/PersonalSetting.jsx (1)

454-459: LGTM!

The turnstileEnabled and turnstileSiteKey props are correctly passed to CheckinCalendar, following the same pattern used for other modals like EmailBindModal and AccountDeleteModal. The props are properly derived from the status state.

web/src/components/settings/personal/cards/CheckinCalendar.jsx (2)

228-239: LGTM!

The Turnstile widget integration is well-implemented:

  • Using key prop to force re-initialization on expiration is the correct pattern for react-turnstile
  • onVerify properly passes the token to doCheckin
  • onExpire correctly refreshes the widget

42-46: LGTM!

The component signature properly accepts the new Turnstile-related props, and the state management for modal visibility and widget key is correctly initialized.

@Calcium-Ion
Calcium-Ion merged commit cfc72d6 into QuantumNous:main Jan 3, 2026
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…curity-check

feat: check-in feature integrates Turnstile security check
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…curity-check

feat: check-in feature integrates Turnstile security check
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…curity-check

feat: check-in feature integrates Turnstile security check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants