forked from nixcn/nixcn-cms
@@ -0,0 +1,47 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"nixcn-cms/data"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Update(c *gin.Context) {
|
||||
var ReqInfo data.UserUpdateInput
|
||||
c.BindJSON(&ReqInfo)
|
||||
|
||||
// New user model
|
||||
user := new(data.User)
|
||||
userId, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, 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(http.StatusForbidden, gin.H{
|
||||
"status": "premission denied",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Cant change user type under permission 2
|
||||
if user.PermissionLevel < 2 {
|
||||
ReqInfo.Type = nil
|
||||
}
|
||||
|
||||
// Update user info
|
||||
user.UpdateByUserID(userId.(uuid.UUID), &ReqInfo)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user