ForceLogout

pull/236/head
skiffer-git 2 years ago
parent 4695ef3208
commit 290ae774e0

@ -134,19 +134,30 @@ func ForceLogout(c *gin.Context) {
return return
} }
req := &rpc.ForceLogoutReq{}
utils.CopyStructFields(req, &params)
var ok bool var ok bool
var errInfo string var errInfo string
var expireTime int64 ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
ok, _, errInfo, expireTime = token_verify.GetUserIDFromTokenExpireTime(c.Request.Header.Get("token"), params.OperationID)
if !ok { if !ok {
errMsg := params.OperationID + " " + "GetUserIDFromTokenExpireTime failed " + errInfo + " token:" + c.Request.Header.Get("token") errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
log.NewError(params.OperationID, errMsg) log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return return
} }
resp := api.ParseTokenResp{CommResp: api.CommResp{ErrCode: 0, ErrMsg: ""}, ExpireTime: api.ExpireTime{ExpireTimeSeconds: uint32(expireTime)}} log.NewInfo(req.OperationID, "ForceLogout args ", req.String())
resp.Data = structs.Map(&resp.ExpireTime) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
log.NewInfo(params.OperationID, "ParseToken return ", resp) client := rpc.NewAuthClient(etcdConn)
c.JSON(http.StatusOK, resp) reply, err := client.ForceLogout(context.Background(), req)
if err != nil {
errMsg := req.OperationID + " UserToken failed " + err.Error() + req.String()
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
log.NewInfo(params.OperationID, utils.GetSelfFuncName(), " return ", reply)
c.JSON(http.StatusOK, reply)
} }

@ -83,14 +83,10 @@ func (rpc *rpcAuth) ForceLogout(_ context.Context, req *pbAuth.ForceLogoutReq) (
func (rpc *rpcAuth) forceKickOff(userID string, platformID int32, operationID string) error { func (rpc *rpcAuth) forceKickOff(userID string, platformID int32, operationID string) error {
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
client := pbRelay.NewOnlineMessageRelayServiceClient(etcdConn) client := pbRelay.NewOnlineMessageRelayServiceClient(etcdConn)
kickReq := &pbRelay.KickUserOfflineReq{OperationID: operationID, KickUserIDList: []string{userID}, PlatformID: platformID} kickReq := &pbRelay.KickUserOfflineReq{OperationID: operationID, KickUserIDList: []string{userID}, PlatformID: platformID}
_, err := client.KickUserOffline(context.Background(), kickReq) _, err := client.KickUserOffline(context.Background(), kickReq)
if err != nil {
return utils.Wrap(err, "") return utils.Wrap(err, "")
} }
return nil
}
type rpcAuth struct { type rpcAuth struct {
rpcPort int rpcPort int

@ -40,7 +40,7 @@ type UserTokenResp struct {
type ForceLogoutReq struct { type ForceLogoutReq struct {
Platform int32 `json:"platform" binding:"required,min=1,max=8"` Platform int32 `json:"platform" binding:"required,min=1,max=8"`
UserID string `json:"userID" binding:"required,min=1,max=64"` FromUserID string `json:"fromUserID" binding:"required,min=1,max=64"`
OperationID string `json:"operationID" binding:"required"` OperationID string `json:"operationID" binding:"required"`
} }

Loading…
Cancel
Save