update
parent
82cce14ef8
commit
d68e8aa6b1
|
@ -54,6 +54,7 @@ func ApiLogin(c *gin.Context) {
|
|||
}
|
||||
err = SetClaims(c, &Claims{
|
||||
Uid: usr.ID,
|
||||
User: usr.Username,
|
||||
Groups: grps,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -15,9 +15,11 @@ import (
|
|||
)
|
||||
|
||||
const GinClaimKey = "claim"
|
||||
const GinUserKey = "user"
|
||||
|
||||
type Claims struct {
|
||||
Uid string `json:"uid,omitempty"`
|
||||
User string `json:"usr,omitempty"`
|
||||
Groups []string `json:"grp,omitempty"`
|
||||
Endpoint string `json:"ept,omitempty"`
|
||||
IP string `json:"ip,omitempty"`
|
||||
|
@ -155,6 +157,7 @@ func (srv Auth) Middleware(c *gin.Context) {
|
|||
claims, err := srv.GetClaims(c)
|
||||
if err == nil {
|
||||
c.Set(GinClaimKey, claims)
|
||||
c.Set(GinUserKey, claims.User)
|
||||
if srv.AutoRenew && claims.ExpiresAt != 0 {
|
||||
claims.ExpiresAt = time.Now().Unix() + srv.TokenExpire
|
||||
tok, err := srv.NewToken(*claims)
|
||||
|
|
|
@ -39,6 +39,9 @@ func (srv *Service) Default(c *gin.Context) {
|
|||
if srv.SkipLog != nil && srv.SkipLog(c) {
|
||||
return
|
||||
}
|
||||
if usr, ok := c.Get("user"); ok {
|
||||
cl.Str("user", usr.(string))
|
||||
}
|
||||
cl.
|
||||
Str("method", c.Request.Method).
|
||||
Str("ip", c.ClientIP()).
|
||||
|
|
Loading…
Reference in New Issue