sum7
/
yaja
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
yaja/model/account.go

64 lines
1.1 KiB
Go
Raw Permalink Normal View History

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