3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-15 00:19:29 +01:00
Add more clarify in NS INFO and SAREGISTER about unregistered nicknames
This commit is contained in:
Shivaram Lingamneni 2022-05-05 01:04:28 -04:00
parent 03092769e7
commit b11dc1c84c
4 changed files with 26 additions and 3 deletions

View File

@ -433,7 +433,7 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
// can't register an account with the same name as a registered nick
if am.NickToAccount(account) != "" {
return errAccountAlreadyRegistered
return errNameReserved
}
return am.server.store.Update(func(tx *buntdb.Tx) error {
@ -1480,6 +1480,22 @@ func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount,
return
}
func (am *AccountManager) accountWasUnregistered(accountName string) (result bool) {
casefoldedAccount, err := CasefoldName(accountName)
if err != nil {
return false
}
unregisteredKey := fmt.Sprintf(keyAccountUnregistered, casefoldedAccount)
am.server.store.View(func(tx *buntdb.Tx) error {
if _, err := tx.Get(unregisteredKey); err == nil {
result = true
}
return nil
})
return
}
// look up the unfolded version of an account name, possibly after deletion
func (am *AccountManager) AccountToAccountName(account string) (result string) {
casefoldedAccount, err := CasefoldName(account)

View File

@ -74,6 +74,7 @@ var (
errRegisteredOnly = errors.New("Cannot join registered-only channel without an account")
errValidEmailRequired = errors.New("A valid email address is required for account registration")
errInvalidAccountRename = errors.New("Account renames can only change the casefolding of the account name")
errNameReserved = errors.New(`Name reserved due to a prior registration`)
)
// String Errors

View File

@ -69,7 +69,7 @@ func registrationErrorToMessage(config *Config, client *Client, err error) (mess
}
switch err {
case errAccountAlreadyRegistered, errAccountAlreadyVerified, errAccountAlreadyUnregistered, errAccountAlreadyLoggedIn, errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled, errAccountBadPassphrase:
case errAccountAlreadyRegistered, errAccountAlreadyVerified, errAccountAlreadyUnregistered, errAccountAlreadyLoggedIn, errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled, errAccountBadPassphrase, errNameReserved:
message = err.Error()
case errLimitExceeded:
message = `There have been too many registration attempts recently; try again later`

View File

@ -913,7 +913,11 @@ func nsInfoHandler(service *ircService, server *Server, client *Client, command
account, err := server.accounts.LoadAccount(accountName)
if err != nil || !account.Verified {
service.Notice(rb, client.t("Account does not exist"))
if server.accounts.accountWasUnregistered(accountName) {
service.Notice(rb, client.t("Name reserved due to a prior registration"))
} else {
service.Notice(rb, client.t("Account does not exist"))
}
return
}
@ -1025,6 +1029,8 @@ func nsSaregisterHandler(service *ircService, server *Server, client *Client, co
var errMsg string
if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified {
errMsg = client.t("Account already exists")
} else if err == errNameReserved {
errMsg = client.t(err.Error())
} else if err == errAccountBadPassphrase {
errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid")
} else {