User Module
The User Module (/users) is the core of the identity system. It handles the lifecycle of user accounts, their profile management, and relationships with other system entities.
Data Model
The User entity is the central node in the RBAC graph.
- Relations:
roles: Many-to-Many relation with theRoleentity.department: Many-to-One relation with theDepartmententity.sessions: One-to-Many relation with activeUserSessionrecords.
- Security Fields:
password: Stored as a bcrypt hash. Never returned in API responses.totpSecret: Encrypted secret for MFA.recoveryCodes: Encrypted backup codes.
User Management (/users)
These endpoints are primarily used by the Admin UI for user administration.
List Users (
GET /users)- Supports pagination (
page,pageSize). - Filters:
username,realName,deptId(recursive),status,roleId. - Returns a list of users with their associated Department and Role names.
- Supports pagination (
Create User (
POST /users)- Logic:
- Checks for duplicate usernames.
- Hashes the default password (if not provided).
- Connects relations (Roles, Dept).
- Logic:
Update User (
PUT /users/:id)- Updates profile fields.
- Note: Password updates are handled via a separate endpoint for security.
- Status Change: If a user is disabled (
status: 0), their active sessions are immediately revoked.
Delete User (
DELETE /users/:id)- Hard Delete: Currently implements a hard delete (removes the record).
- Constraint: Cannot delete the currently logged-in user (Self-protection).
Profile Management (/users/me)
These endpoints are for the currently authenticated user to manage their own account.
Get Profile (
GET /users/me)- Returns the full profile of the current user.
- Includes
permissionslist (merged from all roles) for frontend access control.
Update Profile (
PUT /users/me)- Allows updating:
realName,avatar,homePath. - Restricted: Users cannot change their own
username,roles, ordepartmentvia this endpoint.
- Allows updating:
Change Password (
PUT /auth/password)- Requires
oldPasswordandnewPassword. - Upon success, all other sessions for this user are revoked.
- Requires