mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
move shared code to pkg.
This commit is contained in:
@ -1,67 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"gitlab.com/demodesk/neko/server/internal/types"
|
||||
"gitlab.com/demodesk/neko/server/internal/utils"
|
||||
)
|
||||
|
||||
type key int
|
||||
|
||||
const keySessionCtx key = iota
|
||||
|
||||
func SetSession(r *http.Request, session types.Session) context.Context {
|
||||
return context.WithValue(r.Context(), keySessionCtx, session)
|
||||
}
|
||||
|
||||
func GetSession(r *http.Request) (types.Session, bool) {
|
||||
session, ok := r.Context().Value(keySessionCtx).(types.Session)
|
||||
return session, ok
|
||||
}
|
||||
|
||||
func AdminsOnly(w http.ResponseWriter, r *http.Request) (context.Context, error) {
|
||||
session, ok := GetSession(r)
|
||||
if !ok || !session.Profile().IsAdmin {
|
||||
return nil, utils.HttpForbidden("session is not admin")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func HostsOnly(w http.ResponseWriter, r *http.Request) (context.Context, error) {
|
||||
session, ok := GetSession(r)
|
||||
if !ok || !session.IsHost() {
|
||||
return nil, utils.HttpForbidden("session is not host")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CanWatchOnly(w http.ResponseWriter, r *http.Request) (context.Context, error) {
|
||||
session, ok := GetSession(r)
|
||||
if !ok || !session.Profile().CanWatch {
|
||||
return nil, utils.HttpForbidden("session cannot watch")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CanHostOnly(w http.ResponseWriter, r *http.Request) (context.Context, error) {
|
||||
session, ok := GetSession(r)
|
||||
if !ok || !session.Profile().CanHost {
|
||||
return nil, utils.HttpForbidden("session cannot host")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CanAccessClipboardOnly(w http.ResponseWriter, r *http.Request) (context.Context, error) {
|
||||
session, ok := GetSession(r)
|
||||
if !ok || !session.Profile().CanAccessClipboard {
|
||||
return nil, utils.HttpForbidden("session cannot access clipboard")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"gitlab.com/demodesk/neko/server/internal/types"
|
||||
"gitlab.com/demodesk/neko/server/pkg/types"
|
||||
)
|
||||
|
||||
func pprofHandler(r types.Router) {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"gitlab.com/demodesk/neko/server/internal/types"
|
||||
"gitlab.com/demodesk/neko/server/internal/utils"
|
||||
"gitlab.com/demodesk/neko/server/pkg/types"
|
||||
"gitlab.com/demodesk/neko/server/pkg/utils"
|
||||
)
|
||||
|
||||
type logFormatter struct {
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"gitlab.com/demodesk/neko/server/internal/config"
|
||||
"gitlab.com/demodesk/neko/server/internal/types"
|
||||
"gitlab.com/demodesk/neko/server/pkg/types"
|
||||
)
|
||||
|
||||
type HttpManagerCtx struct {
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"gitlab.com/demodesk/neko/server/internal/http/auth"
|
||||
"gitlab.com/demodesk/neko/server/internal/types"
|
||||
"gitlab.com/demodesk/neko/server/internal/utils"
|
||||
"gitlab.com/demodesk/neko/server/pkg/auth"
|
||||
"gitlab.com/demodesk/neko/server/pkg/types"
|
||||
"gitlab.com/demodesk/neko/server/pkg/utils"
|
||||
)
|
||||
|
||||
type router struct {
|
||||
|
Reference in New Issue
Block a user