From d1fccf5ab62929c38c191e5df2ec93946cd7329a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 25 Nov 2020 22:07:05 +0100 Subject: [PATCH] MemberProfile as public type & create user on auth. --- internal/session/auth.go | 10 +++------- internal/session/manager.go | 2 +- internal/session/session.go | 18 ++++-------------- internal/types/session.go | 10 ++++++++++ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/internal/session/auth.go b/internal/session/auth.go index 7d9e8c51..2a9bd59d 100644 --- a/internal/session/auth.go +++ b/internal/session/auth.go @@ -6,7 +6,6 @@ import ( "strings" "demodesk/neko/internal/types" - "demodesk/neko/internal/utils" ) const ( @@ -26,12 +25,9 @@ func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session, return nil, fmt.Errorf("invalid password") } - id, err := utils.NewUID(32) - if err != nil { - return nil, err - } - - return manager.New(id, isAdmin), nil + return manager.Create(types.MemberProfile{ + IsAdmin: isAdmin, + }) } func getToken(r *http.Request) string { diff --git a/internal/session/manager.go b/internal/session/manager.go index 8d90d7ea..ec96a889 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -37,7 +37,7 @@ type SessionManagerCtx struct { emmiter events.EventEmmiter } -func (manager *SessionManagerCtx) Create(profile MemberProfile) (types.Session, error) { +func (manager *SessionManagerCtx) Create(profile types.MemberProfile) (types.Session, error) { manager.membersMu.Lock() defer manager.membersMu.Unlock() diff --git a/internal/session/session.go b/internal/session/session.go index 0254a36f..22ded516 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -8,21 +8,11 @@ import ( "demodesk/neko/internal/types/message" ) -type MemberProfile struct { - //token string - name string - is_admin bool - //enabled bool - //can_control bool - //can_watch bool - //clipboard_access bool -} - type SessionCtx struct { id string logger zerolog.Logger manager *SessionManagerCtx - profile MemberProfile + profile types.MemberProfile websocket_peer types.WebSocketPeer websocket_connected bool webrtc_peer types.WebRTCPeer @@ -34,11 +24,11 @@ func (session *SessionCtx) ID() string { } func (session *SessionCtx) Name() string { - return session.profile.name + return session.profile.Name } func (session *SessionCtx) Admin() bool { - return session.profile.is_admin + return session.profile.IsAdmin } func (session *SessionCtx) IsHost() bool { @@ -50,7 +40,7 @@ func (session *SessionCtx) Connected() bool { } func (session *SessionCtx) SetName(name string) { - session.profile.name = name + session.profile.Name = name } func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer) { diff --git a/internal/types/session.go b/internal/types/session.go index f141145a..b23d9255 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -2,6 +2,16 @@ package types import "net/http" +type MemberProfile struct { + //Token string + Name string + IsAdmin bool + //Enabled bool + //CanControl bool + //CanWatch bool + //ClipboardAccess bool +} + type Session interface { ID() string Name() string