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 163e85b commit e8885ce
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ 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 || strings.HasPrefix(r.URL.Path, "/api") && r.URL.Query().Get("pass") != conf.Pass {
if strings.HasPrefix(r.URL.Path, "/api") && r.URL.Query().Get("pass") == conf.Pass {
return
}
if cookie, err := r.Cookie("p"); err != nil || cookie.Value != conf.Pass {
http.Redirect(w, r, "/pwd", http.StatusSeeOther)
return
}
Expand Down

0 comments on commit e8885ce

Please sign in to comment.