修复序列化代码
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -40,14 +38,28 @@ func (info *UserInfo) GetIdType() IDTYPE {
|
||||
return IDTYPE_Onlooker
|
||||
}
|
||||
|
||||
// 获取登录信息
|
||||
func GetUserInfoFormCtx(ctx context.Context) UserInfo {
|
||||
uid, err := ctx.Value("user_id").(json.Number).Int64()
|
||||
if err != nil {
|
||||
logx.Error("parse uid form context err:", err.Error())
|
||||
return UserInfo{}
|
||||
// IsUser 用户是不是登录用户
|
||||
func (info *UserInfo) IsUser() bool {
|
||||
return info.UserId != 0
|
||||
}
|
||||
|
||||
// IsGuest 用户是不是游客
|
||||
func (info *UserInfo) IsGuest() bool {
|
||||
// 必须判断登录用户在前, 用户可能会携带以前是游客到注册的身份
|
||||
if info.UserId != 0 {
|
||||
return false
|
||||
}
|
||||
return UserInfo{UserId: uid}
|
||||
|
||||
if info.GuestId != 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsOnlooker 白板用户: 非登录用户, 非游客, 判断为白板用户
|
||||
func (info *UserInfo) IsOnlooker() bool {
|
||||
return info.UserId != 0 && info.GuestId != 0
|
||||
}
|
||||
|
||||
// 获取登录信息
|
||||
|
||||
@@ -13,9 +13,16 @@ var (
|
||||
CodeServiceErr = &StatusResponse{510, "server logic error"} // server logic 错误
|
||||
CodeUnAuth = &StatusResponse{401, "unauthorized"} // 未授权
|
||||
|
||||
CodeUpdateErr = &StatusResponse{5000, "update database error"} // update database logic 错误
|
||||
CodeDupGuestErr = &StatusResponse{5001, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // api参数校验 错误
|
||||
CodeUpdateErr = &StatusResponse{5000, "update database error"} // update database logic 错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // api参数校验 错误
|
||||
|
||||
CodeEmailNotFoundErr = &StatusResponse{5050, "the email was not found"} // email 不存在
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "the user was not found"} // email 不存在
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 密码错误
|
||||
|
||||
CodeGuestDupErr = &StatusResponse{5010, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest_id of the visitor"} // 游客guest_id序列化失败
|
||||
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
||||
Reference in New Issue
Block a user