3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

can't register an account with the same name as a registered nick

This commit is contained in:
Shivaram Lingamneni 2018-03-11 13:59:02 -04:00
parent a022befffe
commit 47b9fe50be

View File

@ -161,7 +161,16 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
setOptions = &buntdb.SetOptions{Expires: true, TTL: ttl} setOptions = &buntdb.SetOptions{Expires: true, TTL: ttl}
} }
err = am.server.store.Update(func(tx *buntdb.Tx) error { err = func() error {
am.serialCacheUpdateMutex.Lock()
defer am.serialCacheUpdateMutex.Unlock()
// can't register an account with the same name as a registered nick
if am.NickToAccount(casefoldedAccount) != "" {
return errAccountAlreadyRegistered
}
return am.server.store.Update(func(tx *buntdb.Tx) error {
_, err := am.loadRawAccount(tx, casefoldedAccount) _, err := am.loadRawAccount(tx, casefoldedAccount)
if err != errAccountDoesNotExist { if err != errAccountDoesNotExist {
return errAccountAlreadyRegistered return errAccountAlreadyRegistered
@ -185,6 +194,7 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
} }
return nil return nil
}) })
}()
if err != nil { if err != nil {
return err return err