Browse Source

Merge pull request #1953 from slingamn/issue1886_unregistered.1

fix #1886
tags/v2.10.0-rc1
Shivaram Lingamneni 2 years ago
parent
commit
c454c45d6a
No account linked to committer's email address
4 changed files with 26 additions and 3 deletions
  1. 17
    1
      irc/accounts.go
  2. 1
    0
      irc/errors.go
  3. 1
    1
      irc/handlers.go
  4. 7
    1
      irc/nickserv.go

+ 17
- 1
irc/accounts.go View File

@@ -433,7 +433,7 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
433 433
 
434 434
 		// can't register an account with the same name as a registered nick
435 435
 		if am.NickToAccount(account) != "" {
436
-			return errAccountAlreadyRegistered
436
+			return errNameReserved
437 437
 		}
438 438
 
439 439
 		return am.server.store.Update(func(tx *buntdb.Tx) error {
@@ -1482,6 +1482,22 @@ func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount,
1482 1482
 	return
1483 1483
 }
1484 1484
 
1485
+func (am *AccountManager) accountWasUnregistered(accountName string) (result bool) {
1486
+	casefoldedAccount, err := CasefoldName(accountName)
1487
+	if err != nil {
1488
+		return false
1489
+	}
1490
+
1491
+	unregisteredKey := fmt.Sprintf(keyAccountUnregistered, casefoldedAccount)
1492
+	am.server.store.View(func(tx *buntdb.Tx) error {
1493
+		if _, err := tx.Get(unregisteredKey); err == nil {
1494
+			result = true
1495
+		}
1496
+		return nil
1497
+	})
1498
+	return
1499
+}
1500
+
1485 1501
 // look up the unfolded version of an account name, possibly after deletion
1486 1502
 func (am *AccountManager) AccountToAccountName(account string) (result string) {
1487 1503
 	casefoldedAccount, err := CasefoldName(account)

+ 1
- 0
irc/errors.go View File

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

+ 1
- 1
irc/handlers.go View File

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

+ 7
- 1
irc/nickserv.go View File

@@ -923,7 +923,11 @@ func nsInfoHandler(service *ircService, server *Server, client *Client, command
923 923
 
924 924
 	account, err := server.accounts.LoadAccount(accountName)
925 925
 	if err != nil || !account.Verified {
926
-		service.Notice(rb, client.t("Account does not exist"))
926
+		if server.accounts.accountWasUnregistered(accountName) {
927
+			service.Notice(rb, client.t("Name reserved due to a prior registration"))
928
+		} else {
929
+			service.Notice(rb, client.t("Account does not exist"))
930
+		}
927 931
 		return
928 932
 	}
929 933
 
@@ -1035,6 +1039,8 @@ func nsSaregisterHandler(service *ircService, server *Server, client *Client, co
1035 1039
 		var errMsg string
1036 1040
 		if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified {
1037 1041
 			errMsg = client.t("Account already exists")
1042
+		} else if err == errNameReserved {
1043
+			errMsg = client.t(err.Error())
1038 1044
 		} else if err == errAccountBadPassphrase {
1039 1045
 			errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid")
1040 1046
 		} else {

Loading…
Cancel
Save