From 245c3d9635242a5d9a5085e0b43a42c3de091722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Tue, 29 Dec 2020 22:00:28 +0100 Subject: [PATCH] add CanHostOnly. --- internal/http/auth/auth.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/http/auth/auth.go b/internal/http/auth/auth.go index e1cbd356..de1ebcfc 100644 --- a/internal/http/auth/auth.go +++ b/internal/http/auth/auth.go @@ -55,3 +55,14 @@ func HostsOrAdminsOnly(next http.Handler) http.Handler { } }) } + +func CanHostOnly(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + session := GetSession(r) + if !session.CanHost() { + utils.HttpForbidden(w, "Only for members, that can host.") + } else { + next.ServeHTTP(w, r) + } + }) +}