More adjusting email sending behavior

This commit is contained in:
Noah Petherbridge 2024-09-09 20:59:46 -07:00
parent 463253dbb5
commit 79ea384d40
4 changed files with 27 additions and 15 deletions

View File

@ -50,7 +50,11 @@ const (
ResetPasswordRedisKey = "reset-password/%s"
ChangeEmailRedisKey = "change-email/%s"
SignupTokenExpires = 24 * time.Hour // used for all tokens so far
EmailDebounceExpires = 24 * time.Hour // how to rate limit duplicate mail being sent
// How to rate limit same types of emails being delivered, e.g.
// signups, cert approvals (double post), etc.
EmailDebounceDefault = 24 * time.Hour // default debounce per type of email
EmailDebounceResetPassword = 4 * time.Hour // "forgot password" emails debounce
// Rate limits
RateLimitRedisKey = "rate-limit/%s/%s" // namespace, id

View File

@ -135,7 +135,9 @@ func ForgotPassword() http.HandlerFunc {
return
}
// Email them their reset link.
// Email them their reset link -- if not banned.
if !user.IsBanned() {
if err := mail.LockSending("reset_password", user.Email, config.EmailDebounceResetPassword); err == nil {
if err := mail.Send(mail.Message{
To: user.Email,
Subject: "Reset your forgotten password",
@ -147,6 +149,12 @@ func ForgotPassword() http.HandlerFunc {
}); err != nil {
session.FlashError(w, r, "Error sending an email: %s", err)
}
} else {
log.Error("LockSending: reset_password e-mail is not sent to %s: one was sent recently", user.Email)
}
} else {
log.Error("Do not send 'forgot password' e-mail to %s: user is banned", user.Email)
}
// Success message and redirect away.
session.Flash(w, r, vagueSuccessMessage)

View File

@ -145,7 +145,7 @@ func Signup() http.HandlerFunc {
if user.IsBanned() {
log.Error("Do not send signup e-mail to %s: user is banned", email)
} else {
if err := mail.LockSending("signup", email, config.EmailDebounceExpires); err == nil {
if err := mail.LockSending("signup", email, config.EmailDebounceDefault); err == nil {
err := mail.Send(mail.Message{
To: email,
Subject: "You already have a nonshy account",

View File

@ -434,7 +434,7 @@ func AdminCertification() http.HandlerFunc {
}
// Notify the user via email.
if err := mail.LockSending("cert_rejected", user.Email, config.EmailDebounceExpires); err == nil {
if err := mail.LockSending("cert_rejected", user.Email, config.EmailDebounceDefault); err == nil {
if err := mail.Send(mail.Message{
To: user.Email,
Subject: "Your certification photo has been denied",
@ -507,7 +507,7 @@ func AdminCertification() http.HandlerFunc {
}
// Notify the user via email.
if err := mail.LockSending("cert_approved", user.Email, config.EmailDebounceExpires); err == nil {
if err := mail.LockSending("cert_approved", user.Email, config.EmailDebounceDefault); err == nil {
if err := mail.Send(mail.Message{
To: user.Email,
Subject: "Your certification photo has been approved!",