[PR #340] Replace Change Password with My Profile (email and password update) #328

Open
opened 2026-06-06 22:10:15 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/340
Author: @Akalanka1337
Created: 6/5/2026
Status: 🔄 Open

Base: mainHead: user-profile-email-update


📝 Commits (1)

  • 82bca05 feat(webui): replace Change Password with My Profile (email and password updates)

📊 Changes

15 files changed (+663 additions, -12 deletions)

View changed files

📝 backend/go.mod (+2 -0)
📝 backend/go.sum (+1 -0)
📝 backend/pkg/server/docs/docs.go (+81 -0)
📝 backend/pkg/server/docs/swagger.json (+81 -0)
📝 backend/pkg/server/docs/swagger.yaml (+54 -0)
📝 backend/pkg/server/models/init.go (+1 -0)
📝 backend/pkg/server/models/users.go (+24 -0)
📝 backend/pkg/server/response/errors.go (+3 -0)
📝 backend/pkg/server/response/http_test.go (+3 -0)
📝 backend/pkg/server/router.go (+1 -0)
📝 backend/pkg/server/services/users.go (+83 -0)
📝 backend/pkg/server/services/users_test.go (+90 -0)
📝 frontend/src/components/layouts/main-sidebar.tsx (+11 -12)
frontend/src/features/authentication/email-change-form.tsx (+189 -0)
frontend/src/features/authentication/profile-dialog.tsx (+39 -0)

📄 Description

This PR replaces the simple Change Password option in the user sidebar dropdown with a unified My Profile section. Logged-in local users can now manage their email address (requires their existing password for security) and change their password from a tabbed modal dialog.

Key Changes

Backend

  • New API Endpoint (PUT /api/v1/user/email):
    • Bound under the existing /user router group utilizing the localUserRequired middleware.
    • Implemented password verification (bcrypt.CompareHashAndPassword) to ensure users confirm their identity.
    • Validates that the requested email is not already taken by another user.
    • Invalidates the user cache on update to keep session tokens in sync.
  • Payload Models: Added the EmailChange struct and registered it for validation.
  • Error Responses: Registered specific error definitions (ErrChangeEmailCurrentUserInvalidEmail, ErrChangeEmailCurrentUserInvalidCurrentPassword, ErrChangeEmailCurrentUserEmailAlreadyExists) for accurate error handling.
  • Swagger Specs: Regenerated API docs to include the new endpoint.

Frontend

  • Email Change Form (EmailChangeForm): Added a React Hook Form with Zod validation to submit to the new PUT endpoint.
  • Unified Profile Dialog (ProfileDialog): Added a tabbed modal layout hosting both Update Email and Change Password tabs.
  • Sidebar Integration (MainSidebar): Replaced the "Change Password" item in the user dropdown menu with "My Profile" (using UserIcon).

Verification & Testing

Automated Backend Tests

Added a new unit test suite TestChangeEmailCurrentUser in pkg/server/services/users_test.go covering:

  1. Successful email change.
  2. Mismatched/incorrect password failure.
  3. Duplicate email conflict error.
  4. Malformed email address format validation.
    All package tests pass successfully:
go test -v ./pkg/server/services -run TestChangeEmailCurrentUser
# Output: PASS (TestChangeEmailCurrentUser)

---

<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/340 **Author:** [@Akalanka1337](https://github.com/Akalanka1337) **Created:** 6/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `user-profile-email-update` --- ### 📝 Commits (1) - [`82bca05`](https://github.com/vxcontrol/pentagi/commit/82bca05ac362518606d0332c7b7dc6fce881d917) feat(webui): replace Change Password with My Profile (email and password updates) ### 📊 Changes **15 files changed** (+663 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `backend/go.mod` (+2 -0) 📝 `backend/go.sum` (+1 -0) 📝 `backend/pkg/server/docs/docs.go` (+81 -0) 📝 `backend/pkg/server/docs/swagger.json` (+81 -0) 📝 `backend/pkg/server/docs/swagger.yaml` (+54 -0) 📝 `backend/pkg/server/models/init.go` (+1 -0) 📝 `backend/pkg/server/models/users.go` (+24 -0) 📝 `backend/pkg/server/response/errors.go` (+3 -0) 📝 `backend/pkg/server/response/http_test.go` (+3 -0) 📝 `backend/pkg/server/router.go` (+1 -0) 📝 `backend/pkg/server/services/users.go` (+83 -0) 📝 `backend/pkg/server/services/users_test.go` (+90 -0) 📝 `frontend/src/components/layouts/main-sidebar.tsx` (+11 -12) ➕ `frontend/src/features/authentication/email-change-form.tsx` (+189 -0) ➕ `frontend/src/features/authentication/profile-dialog.tsx` (+39 -0) </details> ### 📄 Description This PR replaces the simple **Change Password** option in the user sidebar dropdown with a unified **My Profile** section. Logged-in local users can now manage their email address (requires their existing password for security) and change their password from a tabbed modal dialog. ### Key Changes #### Backend - **New API Endpoint (`PUT /api/v1/user/email`)**: - Bound under the existing `/user` router group utilizing the `localUserRequired` middleware. - Implemented password verification (`bcrypt.CompareHashAndPassword`) to ensure users confirm their identity. - Validates that the requested email is not already taken by another user. - Invalidates the user cache on update to keep session tokens in sync. - **Payload Models**: Added the `EmailChange` struct and registered it for validation. - **Error Responses**: Registered specific error definitions (`ErrChangeEmailCurrentUserInvalidEmail`, `ErrChangeEmailCurrentUserInvalidCurrentPassword`, `ErrChangeEmailCurrentUserEmailAlreadyExists`) for accurate error handling. - **Swagger Specs**: Regenerated API docs to include the new endpoint. #### Frontend - **Email Change Form (`EmailChangeForm`)**: Added a React Hook Form with Zod validation to submit to the new PUT endpoint. - **Unified Profile Dialog (`ProfileDialog`)**: Added a tabbed modal layout hosting both **Update Email** and **Change Password** tabs. - **Sidebar Integration (`MainSidebar`)**: Replaced the "Change Password" item in the user dropdown menu with "My Profile" (using `UserIcon`). --- ## Verification & Testing ### Automated Backend Tests Added a new unit test suite `TestChangeEmailCurrentUser` in `pkg/server/services/users_test.go` covering: 1. Successful email change. 2. Mismatched/incorrect password failure. 3. Duplicate email conflict error. 4. Malformed email address format validation. All package tests pass successfully: ```bash go test -v ./pkg/server/services -run TestChangeEmailCurrentUser # Output: PASS (TestChangeEmailCurrentUser) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:10:15 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#328