mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-30 22:42:29 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
# Conflicts: # pkg/common/constant/errors.go
This commit is contained in:
commit
425ba5946f
@ -115,7 +115,18 @@ func (s *groupServer) Run() {
|
|||||||
log.NewInfo("", "group rpc success")
|
log.NewInfo("", "group rpc success")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OperationID(ctx context.Context) string {
|
||||||
|
s, _ := ctx.Value("operationID").(string)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpUserID(ctx context.Context) string {
|
||||||
|
s, _ := ctx.Value("opUserID").(string)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
||||||
|
|
||||||
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
|
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||||
if err := token_verify.CheckAccessV2(ctx, req.OpUserID, req.OwnerUserID); err != nil {
|
if err := token_verify.CheckAccessV2(ctx, req.OpUserID, req.OwnerUserID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -133,17 +144,17 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
userIDs = append(userIDs, req.OwnerUserID)
|
userIDs = append(userIDs, req.OwnerUserID)
|
||||||
}
|
}
|
||||||
if groupOwnerNum != 1 {
|
if groupOwnerNum != 1 {
|
||||||
return nil, utils.Wrap(&constant.ErrArgs, "")
|
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||||
}
|
}
|
||||||
if utils.IsRepeatStringSlice(userIDs) {
|
if utils.IsRepeatStringSlice(userIDs) {
|
||||||
return nil, utils.Wrap(&constant.ErrArgs, "")
|
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||||
}
|
}
|
||||||
users, err := rocksCache.GetUserInfoFromCacheBatch(ctx, userIDs)
|
users, err := rocksCache.GetUserInfoFromCacheBatch(ctx, userIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(users) != len(userIDs) {
|
if len(users) != len(userIDs) {
|
||||||
return nil, utils.Wrap(&constant.ErrArgs, "")
|
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||||
}
|
}
|
||||||
userMap := make(map[string]*imdb.User)
|
userMap := make(map[string]*imdb.User)
|
||||||
for i, user := range users {
|
for i, user := range users {
|
||||||
@ -272,15 +283,15 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|||||||
resp := &pbGroup.InviteUserToGroupResp{}
|
resp := &pbGroup.InviteUserToGroupResp{}
|
||||||
|
|
||||||
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
|
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||||
constant.SetErrorForResp(&constant.ErrIdentity, resp.CommonResp)
|
constant.SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return nil, utils.Wrap(&constant.ErrIdentity, "")
|
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||||
}
|
}
|
||||||
groupInfo, err := (*imdb.Group)(nil).Take(ctx, req.GroupID)
|
groupInfo, err := (*imdb.Group)(nil).Take(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||||
return nil, utils.Wrap(&constant.ErrDismissedAlready, "")
|
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
|
||||||
}
|
}
|
||||||
if groupInfo.NeedVerification == constant.AllNeedVerification &&
|
if groupInfo.NeedVerification == constant.AllNeedVerification &&
|
||||||
!imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
|
!imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||||
@ -463,7 +474,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if opInfo.RoleLevel == constant.GroupOrdinaryUsers {
|
if opInfo.RoleLevel == constant.GroupOrdinaryUsers {
|
||||||
return nil, utils.Wrap(&constant.ErrNoPermission, "")
|
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||||
} else if opInfo.RoleLevel == constant.GroupOwner {
|
} else if opInfo.RoleLevel == constant.GroupOwner {
|
||||||
opFlag = 2 //owner
|
opFlag = 2 //owner
|
||||||
} else {
|
} else {
|
||||||
@ -477,7 +488,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
|||||||
if len(req.KickedUserIDList) == 0 {
|
if len(req.KickedUserIDList) == 0 {
|
||||||
//log.NewError(req.OperationID, "failed, kick list 0")
|
//log.NewError(req.OperationID, "failed, kick list 0")
|
||||||
//return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}, nil
|
//return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}, nil
|
||||||
return nil, utils.Wrap(&constant.ErrArgs, "")
|
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||||
}
|
}
|
||||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, req.KickedUserIDList); err != nil {
|
if err := s.DelGroupAndUserCache(ctx, req.GroupID, req.KickedUserIDList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -584,7 +595,7 @@ func FillGroupInfoByGroupID(operationID, groupID string, groupInfo *open_im_sdk.
|
|||||||
}
|
}
|
||||||
if group.Status == constant.GroupStatusDismissed {
|
if group.Status == constant.GroupStatusDismissed {
|
||||||
log.Debug(operationID, " group constant.GroupStatusDismissed ", group.GroupID)
|
log.Debug(operationID, " group constant.GroupStatusDismissed ", group.GroupID)
|
||||||
return utils.Wrap(&constant.ErrDismissedAlready, "")
|
return utils.Wrap(constant.ErrDismissedAlready, "")
|
||||||
}
|
}
|
||||||
return utils.Wrap(cp.GroupDBCopyOpenIM(groupInfo, group), "")
|
return utils.Wrap(cp.GroupDBCopyOpenIM(groupInfo, group), "")
|
||||||
}
|
}
|
||||||
@ -611,7 +622,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
|
|||||||
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
|
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||||
err := FillGroupInfoByGroupID(req.OperationID, v.GroupID, node.GroupInfo)
|
err := FillGroupInfoByGroupID(req.OperationID, v.GroupID, node.GroupInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(errors.Unwrap(err), &constant.ErrDismissedAlready) {
|
if !errors.Is(errors.Unwrap(err), constant.ErrDismissedAlready) {
|
||||||
errResult = err
|
errResult = err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -655,7 +666,7 @@ func CheckPermission(ctx context.Context, groupID string, userID string) (err er
|
|||||||
trace_log.SetCtxInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID)
|
trace_log.SetCtxInfo(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID)
|
||||||
}()
|
}()
|
||||||
if !token_verify.IsManagerUserID(userID) && !imdb.IsGroupOwnerAdmin(groupID, userID) {
|
if !token_verify.IsManagerUserID(userID) && !imdb.IsGroupOwnerAdmin(groupID, userID) {
|
||||||
return utils.Wrap(&constant.ErrNoPermission, utils.GetSelfFuncName())
|
return utils.Wrap(constant.ErrNoPermission, utils.GetSelfFuncName())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -729,7 +740,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
|||||||
} else if req.HandleResult == constant.GroupResponseRefuse {
|
} else if req.HandleResult == constant.GroupResponseRefuse {
|
||||||
chat.GroupApplicationRejectedNotification(req)
|
chat.GroupApplicationRejectedNotification(req)
|
||||||
} else {
|
} else {
|
||||||
return nil, utils.Wrap(&constant.ErrArgs, "")
|
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
@ -745,8 +756,8 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||||
constant.SetErrorForResp(&constant.ErrDismissedAlready, resp.CommonResp)
|
constant.SetErrorForResp(constant.ErrDismissedAlready, resp.CommonResp)
|
||||||
return nil, utils.Wrap(&constant.ErrDismissedAlready, "")
|
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if groupInfo.NeedVerification == constant.Directly {
|
if groupInfo.NeedVerification == constant.Directly {
|
||||||
@ -795,7 +806,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
|||||||
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
|
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
} else {
|
} else {
|
||||||
constant.SetErrorForResp(&constant.ErrGroupTypeNotSupport, resp.CommonResp)
|
constant.SetErrorForResp(constant.ErrGroupTypeNotSupport, resp.CommonResp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -868,14 +879,14 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
resp := &pbGroup.SetGroupInfoResp{}
|
resp := &pbGroup.SetGroupInfoResp{}
|
||||||
|
|
||||||
if !hasAccess(req) {
|
if !hasAccess(req) {
|
||||||
return nil, utils.Wrap(&constant.ErrIdentity, "")
|
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||||
}
|
}
|
||||||
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
|
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if group.Status == constant.GroupStatusDismissed {
|
if group.Status == constant.GroupStatusDismissed {
|
||||||
return nil, utils.Wrap(&constant.ErrDismissedAlready, "")
|
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
var changedType int32
|
var changedType int32
|
||||||
@ -987,7 +998,7 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbGroup.Trans
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||||
return nil, utils.Wrap(&constant.ErrDismissedAlready, "")
|
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.OldOwnerUserID == req.NewOwnerUserID {
|
if req.OldOwnerUserID == req.NewOwnerUserID {
|
||||||
@ -1123,7 +1134,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
|||||||
resp := &pbGroup.DismissGroupResp{}
|
resp := &pbGroup.DismissGroupResp{}
|
||||||
|
|
||||||
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||||
return nil, utils.Wrap(&constant.ErrIdentity, "")
|
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
||||||
@ -1257,7 +1268,7 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
|
|||||||
//errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
|
//errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
|
||||||
//log.Error(req.OperationID, errMsg)
|
//log.Error(req.OperationID, errMsg)
|
||||||
//return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
|
//return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
|
||||||
return nil, utils.Wrap(&constant.ErrNoPermission, "")
|
return nil, utils.Wrap(constant.ErrNoPermission, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
//mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
|
//mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
|
||||||
@ -1325,7 +1336,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
|||||||
resp := &pbGroup.SetGroupMemberNicknameResp{}
|
resp := &pbGroup.SetGroupMemberNicknameResp{}
|
||||||
|
|
||||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.OpUserID) {
|
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||||
return nil, utils.Wrap(&constant.ErrIdentity, "")
|
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||||
}
|
}
|
||||||
cbReq := &pbGroup.SetGroupMemberInfoReq{
|
cbReq := &pbGroup.SetGroupMemberInfoReq{
|
||||||
GroupID: req.GroupID,
|
GroupID: req.GroupID,
|
||||||
|
@ -23,6 +23,7 @@ var ctxLogger *Logger
|
|||||||
type Logger struct {
|
type Logger struct {
|
||||||
*logrus.Logger
|
*logrus.Logger
|
||||||
Pid int
|
Pid int
|
||||||
|
Type string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -58,6 +59,7 @@ func ctxLoggerInit(moduleName string) *Logger {
|
|||||||
return &Logger{
|
return &Logger{
|
||||||
ctxLogger,
|
ctxLogger,
|
||||||
os.Getpid(),
|
os.Getpid(),
|
||||||
|
"ctxLogger",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +97,7 @@ func loggerInit(moduleName string) *Logger {
|
|||||||
return &Logger{
|
return &Logger{
|
||||||
logger,
|
logger,
|
||||||
os.Getpid(),
|
os.Getpid(),
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
||||||
@ -239,11 +242,13 @@ func ShowLog(ctx context.Context) {
|
|||||||
OperationID := trace_log.GetOperationID(ctx)
|
OperationID := trace_log.GetOperationID(ctx)
|
||||||
if ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo).GinCtx != nil {
|
if ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo).GinCtx != nil {
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
}).Infoln("api: ", t.ApiName)
|
}).Infoln("api: ", t.ApiName)
|
||||||
} else {
|
} else {
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
}).Infoln("rpc: ", t.ApiName)
|
}).Infoln("rpc: ", t.ApiName)
|
||||||
@ -251,6 +256,7 @@ func ShowLog(ctx context.Context) {
|
|||||||
for _, v := range *t.Funcs {
|
for _, v := range *t.Funcs {
|
||||||
if v.Err != nil {
|
if v.Err != nil {
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
@ -259,18 +265,21 @@ func ShowLog(ctx context.Context) {
|
|||||||
switch v.LogLevel {
|
switch v.LogLevel {
|
||||||
case logrus.InfoLevel:
|
case logrus.InfoLevel:
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
case logrus.DebugLevel:
|
case logrus.DebugLevel:
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
case logrus.WarnLevel:
|
case logrus.WarnLevel:
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
|
@ -104,22 +104,22 @@ func GetClaimFromToken(tokensString string) (*Claims, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if ve, ok := err.(*jwt.ValidationError); ok {
|
if ve, ok := err.(*jwt.ValidationError); ok {
|
||||||
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
|
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
|
||||||
return nil, utils.Wrap(&constant.ErrTokenMalformed, "")
|
return nil, utils.Wrap(constant.ErrTokenMalformed, "")
|
||||||
} else if ve.Errors&jwt.ValidationErrorExpired != 0 {
|
} else if ve.Errors&jwt.ValidationErrorExpired != 0 {
|
||||||
return nil, utils.Wrap(&constant.ErrTokenExpired, "")
|
return nil, utils.Wrap(constant.ErrTokenExpired, "")
|
||||||
} else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 {
|
} else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 {
|
||||||
return nil, utils.Wrap(&constant.ErrTokenNotValidYet, "")
|
return nil, utils.Wrap(constant.ErrTokenNotValidYet, "")
|
||||||
} else {
|
} else {
|
||||||
return nil, utils.Wrap(&constant.ErrTokenUnknown, "")
|
return nil, utils.Wrap(constant.ErrTokenUnknown, "")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, utils.Wrap(&constant.ErrTokenUnknown, "")
|
return nil, utils.Wrap(constant.ErrTokenUnknown, "")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if claims, ok := token.Claims.(*Claims); ok && token.Valid {
|
if claims, ok := token.Claims.(*Claims); ok && token.Valid {
|
||||||
return claims, nil
|
return claims, nil
|
||||||
}
|
}
|
||||||
return nil, utils.Wrap(&constant.ErrTokenUnknown, "")
|
return nil, utils.Wrap(constant.ErrTokenUnknown, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ func CheckAccessV2(ctx context.Context, OpUserID string, OwnerUserID string) (er
|
|||||||
if OpUserID == OwnerUserID {
|
if OpUserID == OwnerUserID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return utils.Wrap(&constant.ErrIdentity, open_utils.GetSelfFuncName())
|
return utils.Wrap(constant.ErrIdentity, open_utils.GetSelfFuncName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserIDFromToken(token string, operationID string) (bool, string, string) {
|
func GetUserIDFromToken(token string, operationID string) (bool, string, string) {
|
||||||
@ -211,11 +211,11 @@ func ParseToken(tokensString, operationID string) (claims *Claims, err error) {
|
|||||||
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(operationID, "get token from redis err", err.Error(), claims.UID, claims.Platform)
|
log.NewError(operationID, "get token from redis err", err.Error(), claims.UID, claims.Platform)
|
||||||
return nil, utils.Wrap(&constant.ErrTokenNotExist, "get token from redis err")
|
return nil, utils.Wrap(constant.ErrTokenNotExist, "get token from redis err")
|
||||||
}
|
}
|
||||||
if m == nil {
|
if m == nil {
|
||||||
log.NewError(operationID, "get token from redis err, not in redis ", "m is nil ", claims.UID, claims.Platform)
|
log.NewError(operationID, "get token from redis err, not in redis ", "m is nil ", claims.UID, claims.Platform)
|
||||||
return nil, utils.Wrap(&constant.ErrTokenNotExist, "get token from redis err")
|
return nil, utils.Wrap(constant.ErrTokenNotExist, "get token from redis err")
|
||||||
}
|
}
|
||||||
if v, ok := m[tokensString]; ok {
|
if v, ok := m[tokensString]; ok {
|
||||||
switch v {
|
switch v {
|
||||||
@ -224,13 +224,13 @@ func ParseToken(tokensString, operationID string) (claims *Claims, err error) {
|
|||||||
return claims, nil
|
return claims, nil
|
||||||
case constant.KickedToken:
|
case constant.KickedToken:
|
||||||
log.Error(operationID, "this token has been kicked by other same terminal ", constant.ErrTokenKicked)
|
log.Error(operationID, "this token has been kicked by other same terminal ", constant.ErrTokenKicked)
|
||||||
return nil, utils.Wrap(&constant.ErrTokenKicked, "this token has been kicked by other same terminal ")
|
return nil, utils.Wrap(constant.ErrTokenKicked, "this token has been kicked by other same terminal ")
|
||||||
default:
|
default:
|
||||||
return nil, utils.Wrap(&constant.ErrTokenUnknown, "")
|
return nil, utils.Wrap(constant.ErrTokenUnknown, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.NewError(operationID, "redis token map not find ", constant.ErrTokenNotExist, tokensString)
|
log.NewError(operationID, "redis token map not find ", constant.ErrTokenNotExist, tokensString)
|
||||||
return nil, utils.Wrap(&constant.ErrTokenNotExist, "redis token map not find")
|
return nil, utils.Wrap(constant.ErrTokenNotExist, "redis token map not find")
|
||||||
}
|
}
|
||||||
|
|
||||||
//func MakeTheTokenInvalid(currentClaims *Claims, platformClass string) (bool, error) {
|
//func MakeTheTokenInvalid(currentClaims *Claims, platformClass string) (bool, error) {
|
||||||
@ -260,7 +260,7 @@ func VerifyToken(token, uid string) (bool, error) {
|
|||||||
return false, utils.Wrap(err, "ParseToken failed")
|
return false, utils.Wrap(err, "ParseToken failed")
|
||||||
}
|
}
|
||||||
if claims.UID != uid {
|
if claims.UID != uid {
|
||||||
return false, &constant.ErrTokenUnknown
|
return false, constant.ErrTokenUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
log.NewDebug("", claims.UID, claims.Platform)
|
log.NewDebug("", claims.UID, claims.Platform)
|
||||||
@ -286,11 +286,11 @@ func WsVerifyToken(token, uid string, platformID string, operationID string) (bo
|
|||||||
}
|
}
|
||||||
if claims.UID != uid {
|
if claims.UID != uid {
|
||||||
errMsg := " uid is not same to token uid " + argMsg + " claims.UID: " + claims.UID
|
errMsg := " uid is not same to token uid " + argMsg + " claims.UID: " + claims.UID
|
||||||
return false, utils.Wrap(&constant.ErrTokenDifferentUserID, errMsg), errMsg
|
return false, utils.Wrap(constant.ErrTokenDifferentUserID, errMsg), errMsg
|
||||||
}
|
}
|
||||||
if claims.Platform != constant.PlatformIDToName(utils.StringToInt(platformID)) {
|
if claims.Platform != constant.PlatformIDToName(utils.StringToInt(platformID)) {
|
||||||
errMsg := " platform is not same to token platform " + argMsg + " claims platformID: " + claims.Platform
|
errMsg := " platform is not same to token platform " + argMsg + " claims platformID: " + claims.Platform
|
||||||
return false, utils.Wrap(&constant.ErrTokenDifferentPlatformID, errMsg), errMsg
|
return false, utils.Wrap(constant.ErrTokenDifferentPlatformID, errMsg), errMsg
|
||||||
}
|
}
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), " check ok ", claims.UID, uid, claims.Platform)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), " check ok ", claims.UID, uid, claims.Platform)
|
||||||
return true, nil, ""
|
return true, nil, ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user