mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
IsAdmin + IsConnected.
This commit is contained in:
parent
25fec63455
commit
123fbd8317
@ -26,7 +26,7 @@ func GetSession(r *http.Request) types.Session {
|
||||
func AdminsOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.Admin() {
|
||||
if !session.IsAdmin() {
|
||||
utils.HttpForbidden(w)
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
@ -48,7 +48,7 @@ func HostsOnly(next http.Handler) http.Handler {
|
||||
func HostsOrAdminsOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.IsHost() && !session.Admin() {
|
||||
if !session.IsHost() && !session.IsAdmin() {
|
||||
utils.HttpForbidden(w, "Only host can do this.")
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
|
@ -87,7 +87,7 @@ func (manager *SessionManagerCtx) Delete(id string) error {
|
||||
|
||||
delete(manager.members, id)
|
||||
|
||||
if session.Connected() {
|
||||
if session.IsConnected() {
|
||||
return session.Disconnect("member deleted")
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ func (manager *SessionManagerCtx) Admins() []types.Session {
|
||||
|
||||
var sessions []types.Session
|
||||
for _, session := range manager.members {
|
||||
if !session.Connected() || !session.Admin() {
|
||||
if !session.IsConnected() || !session.IsAdmin() {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ func (manager *SessionManagerCtx) Members() []types.Session {
|
||||
|
||||
var sessions []types.Session
|
||||
for _, session := range manager.members {
|
||||
if !session.Connected() {
|
||||
if !session.IsConnected() {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{})
|
||||
defer manager.membersMu.Unlock()
|
||||
|
||||
for id, session := range manager.members {
|
||||
if !session.Connected() {
|
||||
if !session.IsConnected() {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interfac
|
||||
defer manager.membersMu.Unlock()
|
||||
|
||||
for id, session := range manager.members {
|
||||
if !session.Connected() || !session.Admin() {
|
||||
if !session.IsConnected() || !session.IsAdmin() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ func (session *SessionCtx) Name() string {
|
||||
return session.profile.Name
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Admin() bool {
|
||||
func (session *SessionCtx) IsAdmin() bool {
|
||||
return session.profile.IsAdmin
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ func (session *SessionCtx) VerifySecret(secret string) bool {
|
||||
return session.profile.Secret == secret
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Connected() bool {
|
||||
func (session *SessionCtx) IsConnected() bool {
|
||||
// TODO: Refactor.
|
||||
return session.websocket_connected// && session.webrtc_connected
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ type MemberProfile struct {
|
||||
type Session interface {
|
||||
ID() string
|
||||
Name() string
|
||||
Admin() bool
|
||||
IsAdmin() bool
|
||||
IsHost() bool
|
||||
Connected() bool
|
||||
IsConnected() bool
|
||||
VerifySecret(secret string) bool
|
||||
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
||||
SetWebSocketConnected(connected bool)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.ScreenSize) error {
|
||||
if !session.Admin() {
|
||||
if !session.IsAdmin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if session.Admin() {
|
||||
if session.IsAdmin() {
|
||||
if err := h.systemAdmin(session); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -23,7 +23,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
Event: event.MEMBER_CONNECTED,
|
||||
ID: session.ID(),
|
||||
Name: session.Name(),
|
||||
IsAdmin: session.Admin(),
|
||||
IsAdmin: session.IsAdmin(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
|
@ -28,7 +28,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||
members[session.ID()] = message.MemberData{
|
||||
ID: session.ID(),
|
||||
Name: session.Name(),
|
||||
IsAdmin: session.Admin(),
|
||||
IsAdmin: session.IsAdmin(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e
|
||||
return connection.Close()
|
||||
}
|
||||
|
||||
if session.Connected() {
|
||||
if session.IsConnected() {
|
||||
// TODO: Refactor
|
||||
if err = connection.WriteJSON(
|
||||
message.SystemDisconnect{
|
||||
|
Loading…
Reference in New Issue
Block a user