From 89fbbdf31436523b7aa96a780169adfb9a9e81a2 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 28 Oct 2023 16:41:52 +0800 Subject: [PATCH] [add] sui page debug log --- helper/jwt.go | 15 +++++++++++++-- sui/storages/local/page.go | 3 +++ widgets/login/process.go | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/helper/jwt.go b/helper/jwt.go index 6583cfb5..3e771539 100644 --- a/helper/jwt.go +++ b/helper/jwt.go @@ -67,25 +67,34 @@ func JwtMake(id int, data map[string]interface{}, option map[string]interface{}, timeout := int64(3600) uid := fmt.Sprintf("%d", id) subject := "User Token" - audience := "Xiang Metadata Admin Panel" + audience := "Yao Process utils.jwt.Make" issuer := fmt.Sprintf("xiang:%d", id) + if v, has := option["subject"]; has { subject = fmt.Sprintf("%v", v) } + if v, has := option["audience"]; has { audience = fmt.Sprintf("%v", v) } + if v, has := option["issuer"]; has { issuer = fmt.Sprintf("%v", v) } + if v, has := option["sid"]; has { sid = fmt.Sprintf("%v", v) } + if v, has := option["timeout"]; has { timeout = int64(any.Of(v).CInt()) } expiresAt := now + timeout + if v, has := option["expires_at"]; has { + expiresAt = int64(any.Of(v).CInt()) + } + if sid == "" { sid = session.ID() } @@ -107,11 +116,13 @@ func JwtMake(id int, data map[string]interface{}, option map[string]interface{}, Issuer: issuer, // 签发人 }, } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) tokenString, err := token.SignedString([]byte(jwtSecret)) if err != nil { - exception.New("生成令牌失败", 500).Ctx(err).Throw() + exception.New("JWT Make Error: %s", 500, err.Error()).Throw() } + return JwtToken{ Token: tokenString, ExpiresAt: expiresAt, diff --git a/sui/storages/local/page.go b/sui/storages/local/page.go index f171f2bc..05a47572 100644 --- a/sui/storages/local/page.go +++ b/sui/storages/local/page.go @@ -55,6 +55,7 @@ func (tmpl *Template) PageTree(route string) ([]*core.PageTreeNode, error) { tmpl.local.fs.Walk(tmpl.Root, func(root, file string, isdir bool) error { name := filepath.Base(file) relPath := file + log.Debug("[PageTree] file: %s isdir: %v", relPath, isdir) if isdir { if strings.HasPrefix(name, "__") || name == ".tmp" { @@ -79,6 +80,8 @@ func (tmpl *Template) PageTree(route string) ([]*core.PageTreeNode, error) { break } } + + log.Debug("[PageTree] dirs: %s found: %v", dir, found) // If not found, create a new directory node. if !found { newDir := &core.PageTreeNode{ diff --git a/widgets/login/process.go b/widgets/login/process.go index 4e29f0a2..a31a4dea 100644 --- a/widgets/login/process.go +++ b/widgets/login/process.go @@ -99,7 +99,7 @@ func auth(field string, value string, password string, sid string) maps.Map { exception.New("登录密码错误 (%v)", 403, value).Throw() } - expiresAt := time.Now().Unix() + 3600 + expiresAt := time.Now().Unix() + 3600*8 // token := MakeToken(row, expiresAt) id := any.Of(row.Get("id")).CInt()