Files
nixcn-cms/service/user/update.go
2026-01-02 12:36:07 +08:00

53 lines
878 B
Go

package user
import (
"nixcn-cms/data"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
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",
})
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
c.JSON(500, gin.H{
"status": "failed to parse uuid",
})
}
// Get user info
user.GetByUserId(userId)
// Reject permission 0 user
if user.PermissionLevel == 0 {
c.JSON(403, gin.H{
"status": "premission denied",
})
return
}
user.Avatar = ReqInfo.Avatar
user.Email = ReqInfo.Email
user.Nickname = ReqInfo.Nickname
user.Subtitle = ReqInfo.Subtitle
// Update user info
user.UpdateByUserID(userId)
c.JSON(200, gin.H{
"status": "success",
})
}