More adjusting email sending behavior
This commit is contained in:
parent
463253dbb5
commit
79ea384d40
|
@ -50,7 +50,11 @@ const (
|
||||||
ResetPasswordRedisKey = "reset-password/%s"
|
ResetPasswordRedisKey = "reset-password/%s"
|
||||||
ChangeEmailRedisKey = "change-email/%s"
|
ChangeEmailRedisKey = "change-email/%s"
|
||||||
SignupTokenExpires = 24 * time.Hour // used for all tokens so far
|
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
|
// Rate limits
|
||||||
RateLimitRedisKey = "rate-limit/%s/%s" // namespace, id
|
RateLimitRedisKey = "rate-limit/%s/%s" // namespace, id
|
||||||
|
|
|
@ -135,7 +135,9 @@ func ForgotPassword() http.HandlerFunc {
|
||||||
return
|
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{
|
if err := mail.Send(mail.Message{
|
||||||
To: user.Email,
|
To: user.Email,
|
||||||
Subject: "Reset your forgotten password",
|
Subject: "Reset your forgotten password",
|
||||||
|
@ -147,6 +149,12 @@ func ForgotPassword() http.HandlerFunc {
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
session.FlashError(w, r, "Error sending an email: %s", err)
|
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.
|
// Success message and redirect away.
|
||||||
session.Flash(w, r, vagueSuccessMessage)
|
session.Flash(w, r, vagueSuccessMessage)
|
||||||
|
|
|
@ -145,7 +145,7 @@ func Signup() http.HandlerFunc {
|
||||||
if user.IsBanned() {
|
if user.IsBanned() {
|
||||||
log.Error("Do not send signup e-mail to %s: user is banned", email)
|
log.Error("Do not send signup e-mail to %s: user is banned", email)
|
||||||
} else {
|
} 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{
|
err := mail.Send(mail.Message{
|
||||||
To: email,
|
To: email,
|
||||||
Subject: "You already have a nonshy account",
|
Subject: "You already have a nonshy account",
|
||||||
|
|
|
@ -434,7 +434,7 @@ func AdminCertification() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the user via email.
|
// 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{
|
if err := mail.Send(mail.Message{
|
||||||
To: user.Email,
|
To: user.Email,
|
||||||
Subject: "Your certification photo has been denied",
|
Subject: "Your certification photo has been denied",
|
||||||
|
@ -507,7 +507,7 @@ func AdminCertification() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the user via email.
|
// 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{
|
if err := mail.Send(mail.Message{
|
||||||
To: user.Email,
|
To: user.Email,
|
||||||
Subject: "Your certification photo has been approved!",
|
Subject: "Your certification photo has been approved!",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user