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