From b950d8023e067de75e3ea58021f6bc7139d8bf64 Mon Sep 17 00:00:00 2001 From: weloe <1345895607@qq.com> Date: Sat, 13 May 2023 11:07:55 +0800 Subject: [PATCH] feat: add GetLoginCount() to support get login count --- enforcer.go | 7 +++++++ enforcer_interface.go | 1 + 2 files changed, 8 insertions(+) diff --git a/enforcer.go b/enforcer.go index c6d2f37..c8e3e1b 100644 --- a/enforcer.go +++ b/enforcer.go @@ -378,6 +378,13 @@ func (e *Enforcer) GetLoginId(ctx ctx.Context) (string, error) { return str, nil } +func (e *Enforcer) GetLoginCount(id string) int { + if session := e.GetSession(id); session != nil { + return session.TokenSignList.Len() + } + return 0 +} + func (e *Enforcer) Banned(id string, service string) error { panic("implement me ...") } diff --git a/enforcer_interface.go b/enforcer_interface.go index 3392bc1..446302c 100644 --- a/enforcer_interface.go +++ b/enforcer_interface.go @@ -16,6 +16,7 @@ type IEnforcer interface { IsLogin(ctx ctx.Context) (bool, error) IsLoginById(id string) (bool, error) GetLoginId(ctx ctx.Context) (string, error) + GetLoginCount(id string) int Replaced(id string, device string) error // Banned TODO