增加清理老登录SESSION API

This commit is contained in:
GoEdgeLab
2024-05-03 12:09:54 +08:00
parent 5bb0ab9c71
commit cf66887d48
2 changed files with 76 additions and 15 deletions

View File

@@ -84,3 +84,31 @@ func (this *LoginSessionService) FindLoginSession(ctx context.Context, req *pb.F
},
}, nil
}
// ClearOldLoginSessions 清理老的SESSION
func (this *LoginSessionService) ClearOldLoginSessions(ctx context.Context, req *pb.ClearOldLoginSessionsRequest) (*pb.RPCSuccess, error) {
_, _, err := this.ValidateAdminAndUser(ctx, false)
if err != nil {
return nil, err
}
if len(req.Sid) == 0 {
return nil, errors.New("'token' should not be empty")
}
var tx = this.NullTx()
session, err := models.SharedLoginSessionDAO.FindSession(tx, req.Sid)
if err != nil {
return nil, err
}
if session == nil || !session.IsAvailable() {
return nil, errors.New("invalid sid")
}
err = models.SharedLoginSessionDAO.ClearOldSessions(tx, int64(session.AdminId), int64(session.UserId), req.Sid, req.Ip)
if err != nil {
return nil, err
}
return this.Success()
}