mirror of
https://github.com/weloe/token-go.git
synced 2025-10-04 15:12:47 +08:00
feat: add GetId and add validation
This commit is contained in:
10
enforcer.go
10
enforcer.go
@@ -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)
|
||||
|
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user