测试登录验证

This commit is contained in:
eson 2023-08-25 16:19:47 +08:00
parent 7234b06745
commit fb071cf60b

View File

@ -52,16 +52,18 @@ func NormalAfterLogic(w http.ResponseWriter, r *http.Request, resp *Response) {
}
func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx any, LogicRequest any) (*auth.UserInfo, error) {
var userinfo *auth.UserInfo
var err error
// log.Println(io.ReadAll(r.Body))
token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息
if err != nil {
logx.Error(err)
return nil, err
}
if token == "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQyOTM0NjIsImd1ZXN0X2lkIjozNiwiaWF0IjozMTUzNjAwMCwidXNlcl9pZCI6MH0.T7PuRSrinlJu7ZZ1DVqUJLWXhY_6R1lXiUHaNdw35hU" {
userinfo = info
} else {
var secret uint64 = 0
if info != nil {
@ -83,7 +85,6 @@ func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx any, LogicReque
}
}
var userinfo *auth.UserInfo
if secret != 0 {
claims, err := auth.ParseJwtTokenUint64Secret(token, secret)
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
@ -113,6 +114,7 @@ func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx any, LogicReque
// 白板用户
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
}
// 如果端点有请求结构体则使用httpx.Parse方法从HTTP请求体中解析请求数据
if err = httpx.Parse(r, LogicRequest); err != nil {