Verified Commit 9a1ef006 authored by blint's avatar blint 😶
Browse files

add admin middleware

parent ae2d8368
Pipeline #8684 waiting for manual action with stages
in 3 minutes and 11 seconds
......@@ -10,7 +10,8 @@ import (
var adminTemplate *template.Template
var balanceTemplate *template.Template
var Router = http.NewServeMux()
var router = http.NewServeMux()
var Handler = adminMW(router)
type Between struct {
User *homepage.User
......@@ -35,14 +36,30 @@ func init() {
panic(err)
}
Router.HandleFunc("/balance/", balance)
Router.HandleFunc("/", handler)
router.HandleFunc("/balance/", balance)
router.HandleFunc("/", handler)
}
func adminMW(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
admin, err := homepage.GetUserInfoBySession(r)
if err != nil {
helpers.Logger.Println(err)
return
}
if admin.IsAdmin {
h.ServeHTTP(w, r)
} else {
w.WriteHeader(http.StatusForbidden)
}
})
}
func handler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
admin, err := homepage.GetUserInfoBySession(r)
if err != nil {
helpers.Logger.Println(err)
return
}
er := adminTemplate.Execute(w, admin)
......
......@@ -5,3 +5,4 @@ source secret.env
set +o allexport
envsubst < values.yaml | helm upgrade --install --wait becskasszasch . -n apps --values -
......@@ -7,5 +7,5 @@ POSTGRES: "${POSTGRES}"
POSTGRES_PASS: "${POSTGRES_PASS}"
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_DB: "${POSTGRES_DB}"
Tag: "v1.6.2"
Tag: "v1.6.3"
REGISTRY_CONF: "${REGISTRY_CONF}"
......@@ -38,7 +38,7 @@ func main() {
//mux.HandleFunc("/topup/api/", topup.PayPalHandler)
mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/metrics/", promhttp.Handler())
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Router))
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler))
mux.HandleFunc("/history/", history.Handler)
mux.HandleFunc("/", homepage.Handler)
//mux.HandleFunc("/new/", homepage.NewHandler)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment