Modify auth middleware
All checks were successful
Build Backend (NixCN CMS) TeamCity build finished
Build Frontend (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-02 13:00:02 +08:00
parent bd8eecbc7d
commit 4dfd4cd529
10 changed files with 41 additions and 89 deletions

View File

@@ -8,33 +8,27 @@ import (
)
func Update(c *gin.Context) {
var ReqInfo data.User
c.BindJSON(&ReqInfo)
// New user model
user := new(data.User)
userIdOrig, ok := c.Get("user_id")
if !ok {
c.JSON(403, gin.H{
"status": "can not found user id",
})
c.JSON(403, gin.H{"status": "userid error"})
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
c.JSON(500, gin.H{
"status": "failed to parse uuid",
})
c.JSON(500, gin.H{"status": "failed to parse uuid"})
}
var ReqInfo data.User
c.BindJSON(&ReqInfo)
// Get user info
user.GetByUserId(userId)
// Reject permission 0 user
if user.PermissionLevel == 0 {
c.JSON(403, gin.H{
"status": "premission denied",
})
c.JSON(403, gin.H{"status": "premission denied"})
return
}
@@ -46,7 +40,5 @@ func Update(c *gin.Context) {
// Update user info
user.UpdateByUserID(userId)
c.JSON(200, gin.H{
"status": "success",
})
c.JSON(200, gin.H{"status": "success"})
}