Files
nixcn-cms/service/user/update.go
Asai Neko 304e1d95ed
Some checks failed
Build Backend (NixCN CMS) TeamCity build failed
Build Frontend (NixCN CMS) TeamCity build finished
Refactor checkin table to attendance table
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-01-01 14:08:59 +08:00

47 lines
767 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)
userId, ok := c.Get("user_id")
if !ok {
c.JSON(403, gin.H{
"status": "can not found user id",
})
return
}
// Get user info
user.GetByUserId(userId.(uuid.UUID))
// 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.(uuid.UUID))
c.JSON(200, gin.H{
"status": "success",
})
}