Fix: Enhanced user management functionality and cascading data deletion. (#13594)

### What problem does this PR solve?
Fix: Enhanced user management functionality and cascading data deletion.

Added tenant and related data initialization functionality during user
creation, including tenants, user-tenant relationships, LLM
configuration, and root folder.
Added cascading deletion logic for user deletion, ensuring that all
associated data is cleaned up simultaneously when a user is deleted.
Implemented a Werkzeug-compatible password hash algorithm (scrypt) and
verification functionality.
Added multiple DAO methods to support batch data operations and
cascading deletion.
Improved user login processing and added token signing functionality.
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
chanx
2026-03-13 16:53:54 +08:00
committed by GitHub
parent a67fa03584
commit a3e6c2e84a
16 changed files with 850 additions and 66 deletions

View File

@ -128,20 +128,32 @@ func (h *UserHandler) Login(c *gin.Context) {
return
}
// Set Authorization header with access_token
if user.AccessToken != nil {
c.Header("Authorization", *user.AccessToken)
// Sign the access_token using itsdangerous (compatible with Python)
variables := server.GetVariables()
secretKey := variables.SecretKey
authToken, err := utility.DumpAccessToken(*user.AccessToken, secretKey)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeServerError,
"message": "Failed to generate auth token",
"data": false,
})
return
}
// Set Authorization header with signed token
c.Header("Authorization", authToken)
// Set CORS headers
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "*")
c.Header("Access-Control-Allow-Headers", "*")
c.Header("Access-Control-Expose-Headers", "Authorization")
profile := h.userService.GetUserProfile(user)
c.JSON(http.StatusOK, gin.H{
"code": common.CodeSuccess,
"message": "Welcome back!",
"data": user,
"data": profile,
})
}