3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

review fix

This commit is contained in:
Shivaram Lingamneni 2020-10-07 09:04:47 -04:00
parent 6bbedadfd5
commit 7fd5bc8d81
2 changed files with 9 additions and 11 deletions

View File

@ -60,19 +60,18 @@ func parseCallback(spec string, config *Config) (callbackNamespace string, callb
return
}
func registrationErrorToMessageAndCode(err error) (message, code string) {
// default responses: let's be risk-averse about displaying internal errors
// to the clients, especially for something as sensitive as accounts
code = "REG_UNSPECIFIED_ERROR"
message = `Could not register`
func registrationErrorToMessage(err error) (message string) {
switch err {
case errAccountBadPassphrase:
code = "REG_INVALID_CREDENTIAL"
message = err.Error()
case errAccountAlreadyRegistered, errAccountAlreadyVerified, errAccountAlreadyUnregistered, errAccountAlreadyLoggedIn, errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled:
case errAccountAlreadyRegistered, errAccountAlreadyVerified, errAccountAlreadyUnregistered, errAccountAlreadyLoggedIn, errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled, errAccountBadPassphrase:
message = err.Error()
case errLimitExceeded:
message = `There have been too many registration attempts recently; try again later`
case errCallbackFailed:
message = `Could not dispatch verification email`
default:
// default response: let's be risk-averse about displaying internal errors
// to the clients, especially for something as sensitive as accounts
message = `Could not register`
}
return
}
@ -2460,7 +2459,6 @@ func registerHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
case errAccountBadPassphrase:
rb.Add(nil, server.name, "FAIL", "REGISTER", "INVALID_PASSWORD", client.t("Password was invalid"))
case errCallbackFailed:
// TODO detect this in NS REGISTER as well
rb.Add(nil, server.name, "FAIL", "REGISTER", "UNACCEPTABLE_EMAIL", client.t("Could not dispatch verification e-mail"))
default:
rb.Add(nil, server.name, "FAIL", "REGISTER", "UNKNOWN_ERROR", client.t("Could not register"))

View File

@ -873,7 +873,7 @@ func nsRegisterHandler(server *Server, client *Client, command string, params []
}
} else {
// details could not be stored and relevant numerics have been dispatched, abort
message, _ := registrationErrorToMessageAndCode(err)
message := registrationErrorToMessage(err)
nsNotice(rb, client.t(message))
}
}