Skip to content

Go CLI: fix register user - #14665

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix417
May 8, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix417

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

  1. Update API URL
  2. Add password encryption

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@JinHai-CN JinHai-CN added the ci Continue Integration label May 8, 2026
@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR reorganizes the user registration endpoint from /v1/user/register to /api/v1/users, adds client-side password encryption to the CLI registration flow, corrects HTTP method assignments for logout endpoints, standardizes error messages in the login service, and aligns development proxy configuration with the new API routes.

Changes

User Registration API Route Restructuring with Client-Side Password Encryption

Layer / File(s) Summary
API Route Contract
internal/handler/user.go
Swagger documentation updated from @Router /v1/user/register [post] to @Router /api/v1/users [post].
Client-Side Password Encryption
internal/cli/user_command.go
RegisterUser now encrypts plaintext password via EncryptPassword before sending the registration request payload; encryption failures return an error.
Server Routes Configuration
internal/router/router.go
User registration POST route at /v1/user/register is removed; top-level logout corrected to GET /v1/user/logout; protected auth group logout method changed from GET to POST /logout.
Error Message Updates
internal/service/user.go
LoginByEmail error messages updated to lowercase and more descriptive phrasing for unregistered email, password decryption, and credential mismatch scenarios.
Development Proxy Configuration
web/vite.config.ts
Vite dev-server proxy regex group updated to explicitly forward /api/v1/users, /api/v1/auth, /api/v1/users/me, and related routes to the backend upstream at http://127.0.0.1:9384/.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • infiniflow/ragflow#14658: Updates to internal/cli/user_command.go registration flow and related CLI auth wiring complement the password encryption change in this PR.

Poem

🐰 A password encrypted, a route set right,
From /v1/user/register to /api/v1/users bright!
The logout now POST-ed, messages now clear,
The frontend proxy sees what it holds dear.
Registration secured, the bunny hops near! 🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing the register user functionality in the Go CLI, which includes API URL updates and password encryption.
Description check ✅ Passed The description covers the required template sections with specific problem statements and a marked bug fix classification, though details are minimal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@JinHai-CN
JinHai-CN marked this pull request as ready for review May 8, 2026 06:10
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels May 8, 2026

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/router/router.go (1)

93-97: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Swagger annotation for Logout is now inconsistent with the registered GET method

internal/handler/user.go line 337 still reads // @router /v1/user/logout [post], but this PR correctly registers the route as GET /v1/user/logout. The POST logout lives at /api/v1/auth/logout (line 138).

📝 Fix in `internal/handler/user.go`
-// `@Router` /v1/user/logout [post]
+// `@Router` /v1/user/logout [get]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/router/router.go` around lines 93 - 97, Update the Swagger router
annotation for the Logout handler to match the registered GET route: change the
comment in internal/handler/user.go that currently reads "// `@Router`
/v1/user/logout [post]" to use "[get]" so it aligns with the registered route
engine.GET("/v1/user/logout", r.userHandler.Logout); also verify the Logout
method signature in the same file remains compatible with GET requests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/user.go`:
- Around line 321-333: Get rid of the account-enumeration leak by returning the
same generic authentication error when s.userDAO.GetByEmail(req.Email) fails and
when the password verification fails: replace the current distinct message from
the s.userDAO.GetByEmail error branch with the same generic authentication error
used for password mismatch (use common.CodeAuthenticationError and a generic
message like "invalid email or password"), while keeping decryptPassword errors
as server errors; update references in this block (s.userDAO.GetByEmail,
s.decryptPassword, s.VerifyPassword, user.Password) so both "user not found" and
"password mismatch" paths produce the identical authentication response.

---

Outside diff comments:
In `@internal/router/router.go`:
- Around line 93-97: Update the Swagger router annotation for the Logout handler
to match the registered GET route: change the comment in
internal/handler/user.go that currently reads "// `@Router` /v1/user/logout
[post]" to use "[get]" so it aligns with the registered route
engine.GET("/v1/user/logout", r.userHandler.Logout); also verify the Logout
method signature in the same file remains compatible with GET requests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: abc1206f-8bfc-4826-8a0b-e06579815e8f

📥 Commits

Reviewing files that changed from the base of the PR and between a82ae4a and f7571a1.

📒 Files selected for processing (5)
  • internal/cli/user_command.go
  • internal/handler/user.go
  • internal/router/router.go
  • internal/service/user.go
  • web/vite.config.ts

Comment thread internal/service/user.go
Comment on lines 321 to 333
user, err := s.userDAO.GetByEmail(req.Email)
if err != nil {
return nil, common.CodeAuthenticationError, fmt.Errorf("Email: %s is not registered!", req.Email)
return nil, common.CodeAuthenticationError, fmt.Errorf("email: %s is not registered!", req.Email)
}

decryptedPassword, err := s.decryptPassword(req.Password)
if err != nil {
return nil, common.CodeServerError, fmt.Errorf("Fail to crypt password")
return nil, common.CodeServerError, fmt.Errorf("fail to crypt password")
}

if user.Password == nil || !s.VerifyPassword(*user.Password, decryptedPassword) {
return nil, common.CodeAuthenticationError, fmt.Errorf("Email and password do not match!")
return nil, common.CodeAuthenticationError, fmt.Errorf("email and password do not match!")
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid account enumeration via login error messages.

The new message at Line 323 reveals whether an email is registered. This weakens authentication security and allows user enumeration. Please return the same generic authentication error for both “user not found” and “password mismatch” branches.

Suggested patch
 func (s *UserService) LoginByEmail(req *EmailLoginRequest) (*entity.User, common.ErrorCode, error) {
 	user, err := s.userDAO.GetByEmail(req.Email)
 	if err != nil {
-		return nil, common.CodeAuthenticationError, fmt.Errorf("email: %s is not registered!", req.Email)
+		return nil, common.CodeAuthenticationError, fmt.Errorf("invalid email or password")
 	}
@@
 	if user.Password == nil || !s.VerifyPassword(*user.Password, decryptedPassword) {
-		return nil, common.CodeAuthenticationError, fmt.Errorf("email and password do not match!")
+		return nil, common.CodeAuthenticationError, fmt.Errorf("invalid email or password")
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/user.go` around lines 321 - 333, Get rid of the
account-enumeration leak by returning the same generic authentication error when
s.userDAO.GetByEmail(req.Email) fails and when the password verification fails:
replace the current distinct message from the s.userDAO.GetByEmail error branch
with the same generic authentication error used for password mismatch (use
common.CodeAuthenticationError and a generic message like "invalid email or
password"), while keeping decryptPassword errors as server errors; update
references in this block (s.userDAO.GetByEmail, s.decryptPassword,
s.VerifyPassword, user.Password) so both "user not found" and "password
mismatch" paths produce the identical authentication response.

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (a82ae4a) to head (f7571a1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14665   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit ee5ae6f into infiniflow:main May 8, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request May 8, 2026
1 task done
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
### What problem does this PR solve?

1. Update API URL
2. Add password encryption

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Signed-off-by: Jin Hai <[email protected]>
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### What problem does this PR solve?

1. Update API URL
2. Add password encryption

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Signed-off-by: Jin Hai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant