1
0
Fork 0
forked from External/ergo

expose a user-visible error if direct email sending fails

See #1659
This commit is contained in:
Shivaram Lingamneni 2021-07-07 06:35:30 -04:00
parent dcfd8d8fe8
commit 46572b871f
5 changed files with 43 additions and 11 deletions

View file

@ -15,6 +15,8 @@ import (
"time"
"unicode"
"github.com/ergochat/irc-go/ircutils"
"github.com/ergochat/ergo/irc/connection_limits"
"github.com/ergochat/ergo/irc/email"
"github.com/ergochat/ergo/irc/migrations"
@ -460,7 +462,7 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
code, err := am.dispatchCallback(client, account, callbackNamespace, callbackValue)
if err != nil {
am.Unregister(casefoldedAccount, true)
return errCallbackFailed
return &registrationCallbackError{underlying: err}
} else {
return am.server.store.Update(func(tx *buntdb.Tx) error {
_, _, err = tx.Set(verificationCodeKey, code, setOptions)
@ -469,6 +471,28 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
}
}
type registrationCallbackError struct {
underlying error
}
func (r *registrationCallbackError) Error() string {
return `Account verification could not be sent`
}
func registrationCallbackErrorText(config *Config, client *Client, err error) string {
if callbackErr, ok := err.(*registrationCallbackError); ok {
// only expose a user-visible error if we are doing direct sending
if config.Accounts.Registration.EmailVerification.DirectSendingEnabled() {
errorText := ircutils.SanitizeText(callbackErr.underlying.Error(), 350)
return fmt.Sprintf(client.t("Could not dispatch registration e-mail: %s"), errorText)
} else {
return client.t("Could not dispatch registration e-mail")
}
} else {
return ""
}
}
// validatePassphrase checks whether a passphrase is allowed by our rules
func validatePassphrase(passphrase string) error {
// sanity check the length