MemberProfile as public type & create user on auth.

This commit is contained in:
Miroslav Šedivý 2020-11-25 22:07:05 +01:00
parent 665d9d2130
commit d1fccf5ab6
4 changed files with 18 additions and 22 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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) {

View File

@ -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