Add AmIAllowed func to tokens package
This commit is contained in:
parent
20c3beef53
commit
bfa9af930e
|
@ -67,12 +67,13 @@ var (
|
|||
)
|
||||
|
||||
func GetToken(id uint) (*Token, error) {
|
||||
toks.Mu.RLock()
|
||||
toks.Mu.Lock()
|
||||
defer toks.Mu.Unlock()
|
||||
val, exists := toks.Tokmap[id]
|
||||
toks.Mu.RUnlock()
|
||||
if !exists {
|
||||
return nil, ERROR_DONT_HAVE_TOKEN
|
||||
}
|
||||
val.LastActive = time.Now()
|
||||
return val, nil
|
||||
}
|
||||
|
||||
|
@ -138,3 +139,14 @@ func AddToken(id uint) (*Token, error) {
|
|||
toks.Mu.Unlock()
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func AmIAllowed(token string) bool {
|
||||
toks.Mu.Lock()
|
||||
defer toks.Mu.Unlock()
|
||||
val, exists := toks.TokmapRev[token]
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
val.LastActive = time.Now()
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user