Skip to content

Commit

Permalink
中间件判断逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
csznet committed Apr 9, 2024
1 parent d4cbbdd commit 2f0d9c6
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,9 @@ func Middleware(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// 只有当密码设置并且不为"none"时,才进行检查
if conf.Pass != "" && conf.Pass != "none" {
if cookie, err := r.Cookie("p"); err != nil || cookie.Value != conf.Pass {
if r.URL.Path == "/api" {
if r.URL.Query().Get("pass") != conf.Pass {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
} else {
http.Redirect(w, r, "/pwd", http.StatusSeeOther)
return
}
if cookie, err := r.Cookie("p"); err != nil || cookie.Value != conf.Pass || r.URL.Path == "/api" && r.URL.Query().Get("pass") != conf.Pass {
http.Redirect(w, r, "/pwd", http.StatusSeeOther)
return
}
}
next(w, r)
Expand Down

0 comments on commit 2f0d9c6

Please sign in to comment.