refactor(login): 重构登录逻辑并优化用户信息获取
- 移除 controller 中的测试代码和不必要的注释 - 优化 login.go 中的用户信息获取逻辑,从 PlayerService 中获取玩家信息 - 删除 LoginSidInfo.go 中的冗余代码和未使用的函数 - 更新 admin 控制器中的 GetSession 方法,返回用户 ID 和 session - 调整 base_sys_user 模型,移除冗余字段和注释 - 新增 GetPerson 方法在 base_sys_user 服务中获取用户信息 - 在 player 模型中添加 NewPlayerInfo 函数创建默认玩家信息
This commit is contained in:
@@ -44,24 +44,37 @@ func (c *BaseSysUserController) Move(ctx context.Context, req *UserMoveReq) (res
|
||||
return
|
||||
}
|
||||
|
||||
func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq) (res *cool.BaseRes, err error) {
|
||||
func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
|
||||
|
||||
t := cool.GetAdmin(ctx)
|
||||
if t == nil || t.UserId == 0 {
|
||||
|
||||
return cool.Fail("未登录"), nil
|
||||
return &SessionRes{}, nil
|
||||
}
|
||||
retsid, sid, err := blazing_service.NewLoginServiceService().GetSessionId(t.UserId)
|
||||
if err != nil {
|
||||
return cool.Fail(err.Error()), nil
|
||||
return &SessionRes{}, nil
|
||||
|
||||
}
|
||||
res = &SessionRes{}
|
||||
|
||||
t1 := service.NewBaseSysUserService().GetPerson(t.UserId)
|
||||
|
||||
res.Session = retsid
|
||||
|
||||
if !blazing_service.NewPlayerService().IsReg(t1.ID) {
|
||||
res.UserID = int(t1.ID)
|
||||
|
||||
}
|
||||
res = cool.Ok(nil)
|
||||
res.Data = retsid
|
||||
|
||||
if err := share.ShareManager.SaveSession(sid, uint32(t.UserId)); err != nil {
|
||||
return cool.Fail(err.Error()), nil
|
||||
return &SessionRes{}, nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type SessionRes struct {
|
||||
UserID int `json:"userid"`
|
||||
Session string `json:"session"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user