cache ValidateAuthToken
This commit is contained in:
parent
7f98182e94
commit
fe48c8cb73
15
login.go
15
login.go
@ -85,6 +85,17 @@ func (api *API) loginPostHandler(m LoginModel) func(c *gin.Context) {
|
||||
|
||||
// ValidateAuthToken checks if token is valid and returns its data
|
||||
func (c *Context) ValidateAuthToken() (tokenObject map[string]interface{}, tokenType string, err error) {
|
||||
|
||||
tokenObject = c.GetStringMap("validate-auth-token-object")
|
||||
if tokenObject != nil {
|
||||
tokenType = c.GetString("validate-auth-token-type")
|
||||
_err, _ := c.Get("validate-auth-token-err")
|
||||
if _err != nil {
|
||||
err = _err.(error)
|
||||
}
|
||||
return // return cached data
|
||||
}
|
||||
|
||||
token := c.Request.Header.Get(c.API.authenticationHeader)
|
||||
if token == "" {
|
||||
return nil, "", errors.New("empty token")
|
||||
@ -110,5 +121,9 @@ func (c *Context) ValidateAuthToken() (tokenObject map[string]interface{}, token
|
||||
return nil, "", errors.New("token object type is invalid")
|
||||
}
|
||||
|
||||
c.Set("validate-auth-token-object", _object)
|
||||
c.Set("validate-auth-token-type", _type)
|
||||
c.Set("validate-auth-token-err", err)
|
||||
|
||||
return _object, _type, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user