Skip to content

Commit

Permalink
fix: apiToken 无法获取工具&api-token 页面不能刷新 #51
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Dec 14, 2024
1 parent 913f85d commit 3056567
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public
.dev
*.py
requirements.txt
.DS_Store
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ act.secret
.dev
*.py
requirements.txt

.DS_Store
2 changes: 1 addition & 1 deletion database/operations.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

func HasApiToken(token string) bool {
sql := `SELECT value FROM nav_api_token WHERE value = ?`
sql := `SELECT value FROM nav_api_token WHERE value = ? and disabled = 0`
rows, err := DB.Query(sql, token)
if err != nil {
return false
Expand Down
2 changes: 2 additions & 0 deletions middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func JWTMiddleware() gin.HandlerFunc {
}

if database.HasApiToken(rawToken) {
c.Set("username", "apiToken")
c.Set("uid", 1)
c.Next()
return
}
Expand Down
2 changes: 1 addition & 1 deletion serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Serve(urlPrefix string, fs ServeFileSystem) gin.HandlerFunc {
c.Abort()
} else {
path := c.Request.URL.Path
pathHasAPI := strings.Contains(path, "/api")
pathHasAPI := strings.Contains(path, "/api") && !strings.Contains(path, "/api-token")
// pathHasAdmin := strings.Contains(path, "/admin")
// pathHasLogin := strings.Contains(path, "/login")
if pathHasAPI {
Expand Down

0 comments on commit 3056567

Please sign in to comment.