Initial commit
This commit is contained in:
16
cpone-dashboard/menu/auth/middleware.go
Normal file
16
cpone-dashboard/menu/auth/middleware.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package auth
|
||||
|
||||
import "net/http"
|
||||
|
||||
func Require(secret string) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
username := getSession(r, secret)
|
||||
if username == "" {
|
||||
http.Redirect(w, r, basePath+"/mcu-login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, setContext(r, username))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user