marvzhang
2020-04-21 13:31:11 +08:00
parent f5941f77d0
commit 8a4a1d91c1
2 changed files with 8 additions and 0 deletions

View File

@@ -98,6 +98,11 @@ func PutUser(c *gin.Context) {
// UserId
uid := services.GetCurrentUserId(c)
// 空 UserId 处理
if uid == "" {
uid = bson.ObjectIdHex(constants.ObjectIdNull)
}
// 添加用户
if err := services.CreateNewUser(reqData.Username, reqData.Password, reqData.Role, reqData.Email, uid); err != nil {
HandleError(http.StatusInternalServerError, c, err)

View File

@@ -114,6 +114,9 @@ func CreateNewUser(username string, password string, role string, email string,
func GetCurrentUser(c *gin.Context) *model.User {
data, _ := c.Get(constants.ContextUser)
if data == nil {
return &model.User{}
}
return data.(*model.User)
}