Skip to content

feat: support first bind update password - #2520

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/605b416fd8a103003cc6ae065b87c371a2f135f0
Dec 26, 2025
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/605b416fd8a103003cc6ae065b87c371a2f135f0

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Dec 25, 2025 •

Copy link
Copy Markdown
Member

支持第三方登录后修改密码,
以支持通过用户名密码登录

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced password validation to support initial account binding, allowing users to set passwords without original password verification during first-time setup.
  • Improvements

    • Streamlined password update workflow for initial configuration scenarios.

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

@coderabbitai

coderabbitai Bot commented Dec 25, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes enable initial password binding by relaxing validation requirements in both backend and frontend. The backend now skips original password validation when no current password exists, while the frontend removes the empty original password check, allowing first-time password creation without pre-existing credentials.

Changes

Cohort / File(s) Summary
Backend password validation
controller/user.go
Modified checkUpdatePassword to conditionally validate original password only when the current password is not empty, bypassing validation for initial password binding scenarios
Frontend password change form
web/src/components/settings/PersonalSetting.jsx
Removed validation check requiring non-empty original_password in changePassword, allowing password change flow to proceed without pre-existing password

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes


🐰 A password unbound takes flight,
No prior key to check tonight,
First binding's charm, a fresh delight,
Backend and frontend, both aligned just right! 🔑✨

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 'feat: support first bind update password' directly and clearly describes the main change: enabling password updates during initial account binding, which aligns with both the code modifications and PR objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 (2)
web/src/components/settings/PersonalSetting.jsx (2)

317-320: Remove commented-out code.

Instead of leaving the validation commented out, please remove these lines entirely to keep the codebase clean.

🔎 Proposed fix
-    // if (inputs.original_password === '') {
-    //   showError(t('请输入原密码!'));
-    //   return;
-    // }
     if (inputs.set_new_password === '') {

325-327: Consider improving UX for first-time password binding.

The validation message "新密码需要和原密码不一致!" (new password must differ from original password) may confuse users who are setting their password for the first time via OAuth, as they have no original password. While the logic is functionally correct, consider conditionally showing this check only when an original password exists, or adjusting the error message.

💡 Example improvement
-    if (inputs.original_password === inputs.set_new_password) {
+    if (inputs.original_password !== '' && inputs.original_password === inputs.set_new_password) {
       showError(t('新密码需要和原密码不一致!'));
       return;
     }

This way, the check only applies when the user has provided an original password.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b1a562 and 2f5f979.

📒 Files selected for processing (2)
  • controller/user.go
  • web/src/components/settings/PersonalSetting.jsx
🔇 Additional comments (1)
controller/user.go (1)

768-773: LGTM! The logic correctly handles password validation for OAuth users.

The added condition && currentUser.Password != "" prevents validation errors for OAuth users binding their first password. Since bcrypt hashes have a specific format, attempting to validate an empty password would fail, making this guard clause necessary. The fix maintains security by:

  • Only skipping validation for users without existing passwords (OAuth users)
  • Still requiring the new password to be non-empty
  • Preserving validation for users with existing passwords

@seefs001 seefs001 added the ready to merge It will eventually merge, requiring a final check. label Dec 26, 2025
@Calcium-Ion
Calcium-Ion merged commit 9aeef6a into QuantumNous:main Dec 26, 2025
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge It will eventually merge, requiring a final check.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants