ForceLogout

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

@ -134,19 +134,30 @@ func ForceLogout(c *gin.Context) {
return
}
req := &rpc.ForceLogoutReq{}
utils.CopyStructFields(req, &params)
var ok bool
var errInfo string
var expireTime int64
ok, _, errInfo, expireTime = token_verify.GetUserIDFromTokenExpireTime(c.Request.Header.Get("token"), params.OperationID)
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
if !ok {
errMsg := params.OperationID + " " + "GetUserIDFromTokenExpireTime failed " + errInfo + " token:" + c.Request.Header.Get("token")
log.NewError(params.OperationID, errMsg)
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
resp := api.ParseTokenResp{CommResp: api.CommResp{ErrCode: 0, ErrMsg: ""}, ExpireTime: api.ExpireTime{ExpireTimeSeconds: uint32(expireTime)}}
resp.Data = structs.Map(&resp.ExpireTime)
log.NewInfo(params.OperationID, "ParseToken return ", resp)
c.JSON(http.StatusOK, resp)
log.NewInfo(req.OperationID, "ForceLogout args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
client := rpc.NewAuthClient(etcdConn)
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,13 +83,9 @@ func (rpc *rpcAuth) ForceLogout(_ context.Context, req *pbAuth.ForceLogoutReq) (
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)
client := pbRelay.NewOnlineMessageRelayServiceClient(etcdConn)
kickReq := &pbRelay.KickUserOfflineReq{OperationID: operationID, KickUserIDList: []string{userID}, PlatformID: platformID}
_, err := client.KickUserOffline(context.Background(), kickReq)
if err != nil {
return utils.Wrap(err, "")
}
return nil
return utils.Wrap(err, "")
}
type rpcAuth struct {

@ -40,7 +40,7 @@ type UserTokenResp struct {
type ForceLogoutReq struct {
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"`
}

Loading…
Cancel
Save