feat: add GetId and add validation

This commit is contained in:
weloe
2023-09-05 17:00:36 +08:00
parent df39e54be6
commit 71088365cf
2 changed files with 11 additions and 0 deletions

View File

@@ -392,7 +392,16 @@ func (e *Enforcer) IsLoginById(id string) (bool, error) {
return false, error
}
// GetId get id
func (e *Enforcer) GetId(ctx ctx.Context) string {
token := e.GetRequestToken(ctx)
return e.GetIdByToken(token)
}
func (e *Enforcer) GetIdByToken(token string) string {
if token == "" {
return ""
}
return e.adapter.GetStr(e.spliceTokenKey(token))
}
@@ -430,6 +439,7 @@ func (e *Enforcer) CheckLoginByToken(token string) error {
return nil
}
// GetLoginId get id and validate it
func (e *Enforcer) GetLoginId(ctx ctx.Context) (string, error) {
tokenValue := e.GetRequestToken(ctx)
return e.GetLoginIdByToken(tokenValue)

View File

@@ -41,6 +41,7 @@ type IEnforcer interface {
GetLoginId(ctx ctx.Context) (string, error)
GetLoginIdByToken(token string) (string, error)
GetId(ctx ctx.Context) string
GetIdByToken(token string) string
GetLoginCount(id string) int