This commit is contained in:
aozhiwei 2024-11-13 16:32:39 +08:00
parent d5915aa8c6
commit e1ecb6d690
2 changed files with 37 additions and 0 deletions

View File

@ -47,3 +47,37 @@ func (this *UserApi) Login(c *gin.Context) {
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}
func (this *UserApi) Info(c *gin.Context) {
s := c.MustGet(constant.SESSION_KEY).(common.Session)
if s == nil {
return
}
user := new(model.User)
rspObj := struct {
vo.BaseVo
UserInfo vo.User `json:"user_info"`
}{}
nowTime := f5.GetApp().GetRealSeconds()
if err, found := user.Find(s.GetAccountId(), nowTime); err != nil {
f5.RspErr(c, 500, "server internal error")
return
} else if !found {
user.AccountId = s.GetAccountId()
user.Avatar = ""
user.NickName = s.GetNickName()
user.Score = 0
user.Dice = mt.Table.Global.GetDailyDiceNum()
user.LastPresentDiceTime = q5.ToInt32(nowTime)
user.CreateTime = q5.ToInt32(nowTime)
user.ModifyTime = q5.ToInt32(nowTime)
if user.Create() != nil {
f5.RspErr(c, 500, "server internal error")
return
}
f5.GetMsgQueue().FireEvent(constant.MSG_CREATE_USER, q5.Args{user})
}
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}

View File

@ -13,4 +13,7 @@ func (this *UserRouter) InitRouter() {
f5.GetApp().GetGinEngine().POST("/api/v1/user/login",
middleware.JwtAuth,
api.UserApi.Login)
f5.GetApp().GetGinEngine().POST("/api/v1/user/info",
middleware.JwtAuth,
api.UserApi.Info)
}