update auth middlewares.

This commit is contained in:
Miroslav Šedivý
2021-03-21 21:26:53 +01:00
parent 5a79212b32
commit 0eef9d4d98
3 changed files with 14 additions and 29 deletions

View File

@ -45,11 +45,11 @@ func HostsOnly(next http.Handler) http.Handler {
})
}
func HostsOrAdminsOnly(next http.Handler) http.Handler {
func CanWatchOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.IsHost() && !session.Profile().IsAdmin {
utils.HttpForbidden(w, "Only host can do this.")
if !session.Profile().CanWatch {
utils.HttpForbidden(w, "Only for sessions, that can watch.")
} else {
next.ServeHTTP(w, r)
}
@ -67,11 +67,11 @@ func CanHostOnly(next http.Handler) http.Handler {
})
}
func CanWatchOnly(next http.Handler) http.Handler {
func CanAccessClipboardOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.Profile().CanWatch {
utils.HttpForbidden(w, "Only for sessions, that can watch.")
if !session.Profile().CanAccessClipboard {
utils.HttpForbidden(w, "Only for sessions, that can access clipboard.")
} else {
next.ServeHTTP(w, r)
}