mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +01:00
can't register an account with the same name as a registered nick
This commit is contained in:
parent
a022befffe
commit
47b9fe50be
@ -161,30 +161,40 @@ 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 {
|
||||||
_, err := am.loadRawAccount(tx, casefoldedAccount)
|
am.serialCacheUpdateMutex.Lock()
|
||||||
if err != errAccountDoesNotExist {
|
defer am.serialCacheUpdateMutex.Unlock()
|
||||||
|
|
||||||
|
// can't register an account with the same name as a registered nick
|
||||||
|
if am.NickToAccount(casefoldedAccount) != "" {
|
||||||
return errAccountAlreadyRegistered
|
return errAccountAlreadyRegistered
|
||||||
}
|
}
|
||||||
|
|
||||||
if certfp != "" {
|
return am.server.store.Update(func(tx *buntdb.Tx) error {
|
||||||
// make sure certfp doesn't already exist because that'd be silly
|
_, err := am.loadRawAccount(tx, casefoldedAccount)
|
||||||
_, err := tx.Get(certFPKey)
|
if err != errAccountDoesNotExist {
|
||||||
if err != buntdb.ErrNotFound {
|
return errAccountAlreadyRegistered
|
||||||
return errCertfpAlreadyExists
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tx.Set(accountKey, "1", setOptions)
|
if certfp != "" {
|
||||||
tx.Set(accountNameKey, account, setOptions)
|
// make sure certfp doesn't already exist because that'd be silly
|
||||||
tx.Set(registeredTimeKey, registeredTimeStr, setOptions)
|
_, err := tx.Get(certFPKey)
|
||||||
tx.Set(credentialsKey, credStr, setOptions)
|
if err != buntdb.ErrNotFound {
|
||||||
tx.Set(callbackKey, callbackSpec, setOptions)
|
return errCertfpAlreadyExists
|
||||||
if certfp != "" {
|
}
|
||||||
tx.Set(certFPKey, casefoldedAccount, setOptions)
|
}
|
||||||
}
|
|
||||||
return nil
|
tx.Set(accountKey, "1", setOptions)
|
||||||
})
|
tx.Set(accountNameKey, account, setOptions)
|
||||||
|
tx.Set(registeredTimeKey, registeredTimeStr, setOptions)
|
||||||
|
tx.Set(credentialsKey, credStr, setOptions)
|
||||||
|
tx.Set(callbackKey, callbackSpec, setOptions)
|
||||||
|
if certfp != "" {
|
||||||
|
tx.Set(certFPKey, casefoldedAccount, setOptions)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user