2017-10-10 00:54:14 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"sync"
|
2018-02-13 20:05:18 +01:00
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/xmpp/base"
|
2017-10-10 00:54:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Domain struct {
|
2017-12-14 21:30:07 +01:00
|
|
|
FQDN string `json:"-"`
|
|
|
|
Accounts map[string]*Account `json:"users"`
|
2017-10-10 00:54:14 +02:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
func (d *Domain) GetJID() *xmppbase.JID {
|
|
|
|
return &xmppbase.JID{
|
2017-10-10 00:54:14 +02:00
|
|
|
Domain: d.FQDN,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Domain) UpdateAccount(a *Account) error {
|
2018-02-15 22:03:49 +01:00
|
|
|
if a.Local == "" {
|
2017-10-10 00:54:14 +02:00
|
|
|
return errors.New("No localpart exists in account")
|
|
|
|
}
|
|
|
|
d.Lock()
|
2018-02-15 22:03:49 +01:00
|
|
|
d.Accounts[a.Local] = a
|
2017-10-10 00:54:14 +02:00
|
|
|
d.Unlock()
|
|
|
|
a.Domain = d
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Account struct {
|
2018-02-15 22:03:49 +01:00
|
|
|
Local string `json:"-"`
|
2017-12-17 13:31:02 +01:00
|
|
|
Domain *Domain `json:"-"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Roster map[string]*Buddy `json:"roster"`
|
|
|
|
Bookmarks map[string]*Bookmark `json:"bookmarks"`
|
2017-12-14 21:30:07 +01:00
|
|
|
}
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
func NewAccount(jid *xmppbase.JID, password string) *Account {
|
2017-12-14 21:30:07 +01:00
|
|
|
if jid == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &Account{
|
2018-02-15 22:03:49 +01:00
|
|
|
Local: jid.Local,
|
2017-12-14 21:30:07 +01:00
|
|
|
Domain: &Domain{
|
|
|
|
FQDN: jid.Domain,
|
|
|
|
},
|
|
|
|
Password: password,
|
|
|
|
}
|
2017-10-10 00:54:14 +02:00
|
|
|
}
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
func (a *Account) GetJID() *xmppbase.JID {
|
|
|
|
return &xmppbase.JID{
|
2017-10-10 00:54:14 +02:00
|
|
|
Domain: a.Domain.FQDN,
|
2018-02-15 22:03:49 +01:00
|
|
|
Local: a.Local,
|
2017-10-10 00:54:14 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 21:30:07 +01:00
|
|
|
|
|
|
|
func (a *Account) ValidatePassword(password string) bool {
|
|
|
|
return a.Password == password
|
|
|
|
}
|