Преглед изворни кода

fix #1886

Add more clarify in NS INFO and SAREGISTER about unregistered nicknames
tags/v2.10.0-rc1
Shivaram Lingamneni пре 2 година
родитељ
комит
b11dc1c84c
4 измењених фајлова са 26 додато и 3 уклоњено
  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 Прегледај датотеку

@@ -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 {
@@ -1480,6 +1480,22 @@ func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount,
1480 1480
 	return
1481 1481
 }
1482 1482
 
1483
+func (am *AccountManager) accountWasUnregistered(accountName string) (result bool) {
1484
+	casefoldedAccount, err := CasefoldName(accountName)
1485
+	if err != nil {
1486
+		return false
1487
+	}
1488
+
1489
+	unregisteredKey := fmt.Sprintf(keyAccountUnregistered, casefoldedAccount)
1490
+	am.server.store.View(func(tx *buntdb.Tx) error {
1491
+		if _, err := tx.Get(unregisteredKey); err == nil {
1492
+			result = true
1493
+		}
1494
+		return nil
1495
+	})
1496
+	return
1497
+}
1498
+
1483 1499
 // look up the unfolded version of an account name, possibly after deletion
1484 1500
 func (am *AccountManager) AccountToAccountName(account string) (result string) {
1485 1501
 	casefoldedAccount, err := CasefoldName(account)

+ 1
- 0
irc/errors.go Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -913,7 +913,11 @@ func nsInfoHandler(service *ircService, server *Server, client *Client, command
913 913
 
914 914
 	account, err := server.accounts.LoadAccount(accountName)
915 915
 	if err != nil || !account.Verified {
916
-		service.Notice(rb, client.t("Account does not exist"))
916
+		if server.accounts.accountWasUnregistered(accountName) {
917
+			service.Notice(rb, client.t("Name reserved due to a prior registration"))
918
+		} else {
919
+			service.Notice(rb, client.t("Account does not exist"))
920
+		}
917 921
 		return
918 922
 	}
919 923
 
@@ -1025,6 +1029,8 @@ func nsSaregisterHandler(service *ircService, server *Server, client *Client, co
1025 1029
 		var errMsg string
1026 1030
 		if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified {
1027 1031
 			errMsg = client.t("Account already exists")
1032
+		} else if err == errNameReserved {
1033
+			errMsg = client.t(err.Error())
1028 1034
 		} else if err == errAccountBadPassphrase {
1029 1035
 			errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid")
1030 1036
 		} else {

Loading…
Откажи
Сачувај