mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
members database import.
This commit is contained in:
parent
9f452aeb01
commit
b24c217509
@ -58,10 +58,9 @@ func (manager *MembersDatabaseCtx) Delete(id string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *MembersDatabaseCtx) Select(id string) (types.MemberProfile, bool) {
|
func (manager *MembersDatabaseCtx) Select() map[string]types.MemberProfile {
|
||||||
manager.mu.Lock()
|
manager.mu.Lock()
|
||||||
defer manager.mu.Unlock()
|
defer manager.mu.Unlock()
|
||||||
|
|
||||||
profile, ok := manager.profiles[id]
|
return manager.profiles
|
||||||
return profile, ok
|
|
||||||
}
|
}
|
||||||
|
@ -26,17 +26,20 @@ func New(config *config.Session) *SessionManagerCtx {
|
|||||||
emmiter: events.New(),
|
emmiter: events.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Import from Database at startup.
|
// import database users
|
||||||
|
for id, profile := range manager.database.Select() {
|
||||||
|
_ = manager.add(id, profile)
|
||||||
|
}
|
||||||
|
|
||||||
// create default admin account at startup
|
// create default admin account at startup
|
||||||
_, _ = manager.Create("admin", types.MemberProfile{
|
_ = manager.add("admin", types.MemberProfile{
|
||||||
Secret: config.AdminPassword,
|
Secret: config.AdminPassword,
|
||||||
Name: "Administrator",
|
Name: "Administrator",
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
// create default user account at startup
|
// create default user account at startup
|
||||||
_, _ = manager.Create("user", types.MemberProfile{
|
_ = manager.add("user", types.MemberProfile{
|
||||||
Secret: config.Password,
|
Secret: config.Password,
|
||||||
Name: "User",
|
Name: "User",
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
@ -56,7 +59,8 @@ type SessionManagerCtx struct {
|
|||||||
emmiter events.EventEmmiter
|
emmiter events.EventEmmiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile) (types.Session, error) {
|
// TODO: Extract members map + primitives.
|
||||||
|
func (manager *SessionManagerCtx) add(id string, profile types.MemberProfile) types.Session {
|
||||||
session := &SessionCtx{
|
session := &SessionCtx{
|
||||||
id: id,
|
id: id,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
@ -64,6 +68,15 @@ func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile)
|
|||||||
profile: profile,
|
profile: profile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manager.members[id] = session
|
||||||
|
return session
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
|
// members
|
||||||
|
// ---
|
||||||
|
|
||||||
|
func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile) (types.Session, error) {
|
||||||
manager.membersMu.Lock()
|
manager.membersMu.Lock()
|
||||||
|
|
||||||
_, ok := manager.members[id]
|
_, ok := manager.members[id]
|
||||||
@ -78,7 +91,7 @@ func (manager *SessionManagerCtx) Create(id string, profile types.MemberProfile)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.members[id] = session
|
session := manager.add(id, profile)
|
||||||
manager.membersMu.Unlock()
|
manager.membersMu.Unlock()
|
||||||
|
|
||||||
manager.emmiter.Emit("created", session)
|
manager.emmiter.Emit("created", session)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user