整理router,删除多余中单件和路由。退出按键放最上方。
This commit is contained in:
@@ -8,9 +8,11 @@ import (
|
||||
|
||||
"goblog/config"
|
||||
"goblog/database"
|
||||
"goblog/handlers/backend"
|
||||
"goblog/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -54,12 +56,20 @@ func loadSidebarData() (categories []models.Category, tags []models.Tag, postCou
|
||||
|
||||
// loginInfo 从上下文提取登录态信息(供侧边栏系统菜单区分已登录/未登录)
|
||||
func loginInfo(c *gin.Context) (isLoggedIn bool, loginName string) {
|
||||
if _, ok := c.Get("userID"); !ok {
|
||||
tokenString, _ := c.Cookie("token")
|
||||
if tokenString == "" {
|
||||
return false, ""
|
||||
}
|
||||
name, _ := c.Get("username")
|
||||
loginName, _ = name.(string)
|
||||
return true, loginName
|
||||
claims := &backend.Claims{}
|
||||
|
||||
token, err := jwt.ParseWithClaims(tokenString, claims, func(token *jwt.Token) (interface{}, error) {
|
||||
return backend.JWTSecret(), nil
|
||||
})
|
||||
|
||||
if err == nil && token.Valid {
|
||||
return true, claims.Username
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// 首页数据结构
|
||||
|
||||
Reference in New Issue
Block a user