3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-15 08:29:31 +01:00

Merge pull request #1953 from slingamn/issue1886_unregistered.1

fix #1886
This commit is contained in:
Shivaram Lingamneni 2022-05-05 22:40:50 -04:00 committed by GitHub
commit c454c45d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 // can't register an account with the same name as a registered nick
if am.NickToAccount(account) != "" { if am.NickToAccount(account) != "" {
return errAccountAlreadyRegistered return errNameReserved
} }
return am.server.store.Update(func(tx *buntdb.Tx) error { return am.server.store.Update(func(tx *buntdb.Tx) error {
@ -1482,6 +1482,22 @@ func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount,
return 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 // look up the unfolded version of an account name, possibly after deletion
func (am *AccountManager) AccountToAccountName(account string) (result string) { func (am *AccountManager) AccountToAccountName(account string) (result string) {
casefoldedAccount, err := CasefoldName(account) casefoldedAccount, err := CasefoldName(account)

View File

@ -74,6 +74,7 @@ var (
errRegisteredOnly = errors.New("Cannot join registered-only channel without an account") errRegisteredOnly = errors.New("Cannot join registered-only channel without an account")
errValidEmailRequired = errors.New("A valid email address is required for account registration") 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") 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 // String Errors

View File

@ -69,7 +69,7 @@ func registrationErrorToMessage(config *Config, client *Client, err error) (mess
} }
switch err { 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() message = err.Error()
case errLimitExceeded: case errLimitExceeded:
message = `There have been too many registration attempts recently; try again later` message = `There have been too many registration attempts recently; try again later`

View File

@ -923,7 +923,11 @@ func nsInfoHandler(service *ircService, server *Server, client *Client, command
account, err := server.accounts.LoadAccount(accountName) account, err := server.accounts.LoadAccount(accountName)
if err != nil || !account.Verified { 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 return
} }
@ -1035,6 +1039,8 @@ func nsSaregisterHandler(service *ircService, server *Server, client *Client, co
var errMsg string var errMsg string
if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified { if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified {
errMsg = client.t("Account already exists") errMsg = client.t("Account already exists")
} else if err == errNameReserved {
errMsg = client.t(err.Error())
} else if err == errAccountBadPassphrase { } else if err == errAccountBadPassphrase {
errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid") errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid")
} else { } else {