Add account restored email on reactivation from ban/suspend

This commit is contained in:
Patrick Britton 2026-02-06 12:39:18 -06:00
parent d1b01aa5b2
commit e5fd9bcaa5
2 changed files with 35 additions and 3 deletions

View file

@ -504,19 +504,30 @@ func (h *AdminHandler) UpdateUserStatus(c *gin.Context) {
`, targetUserID, oldStatus, req.Status, req.Reason, adminUUID)
// Send notification email
if h.emailService != nil && (req.Status == "banned" || req.Status == "suspended") {
if h.emailService != nil {
var userEmail, displayName string
h.pool.QueryRow(ctx, `SELECT u.email, COALESCE(p.display_name, '') FROM users u LEFT JOIN profiles p ON p.id = u.id WHERE u.id = $1::uuid`, targetUserID).Scan(&userEmail, &displayName)
if userEmail != "" {
go func() {
if req.Status == "banned" {
switch req.Status {
case "banned":
if err := h.emailService.SendBanNotificationEmail(userEmail, displayName, req.Reason); err != nil {
log.Error().Err(err).Str("user", targetUserID).Msg("Failed to send ban notification email")
}
} else if req.Status == "suspended" {
case "suspended":
if err := h.emailService.SendSuspensionNotificationEmail(userEmail, displayName, req.Reason, "7 days"); err != nil {
log.Error().Err(err).Str("user", targetUserID).Msg("Failed to send suspension notification email")
}
case "active":
if oldStatus == "banned" || oldStatus == "suspended" {
reason := req.Reason
if reason == "" {
reason = "Your account has been reviewed and restored."
}
if err := h.emailService.SendAccountRestoredEmail(userEmail, displayName, reason); err != nil {
log.Error().Err(err).Str("user", targetUserID).Msg("Failed to send account restored email")
}
}
}
}()
}

View file

@ -340,6 +340,27 @@ func (s *EmailService) SendPostRemovalEmail(toEmail, toName, reason string, stri
return s.sendEmail(toEmail, toName, subject, htmlBody, textBody)
}
func (s *EmailService) SendAccountRestoredEmail(toEmail, toName, reason string) error {
subject := "Your Sojorn account has been restored"
title := "Account Restored"
header := "Welcome back!"
content := fmt.Sprintf(`
<p>Hi %s,</p>
<p>Great news your Sojorn account has been <strong>restored</strong> and is fully active again.</p>
<p style="background: #F0FDF4; border-left: 4px solid #22C55E; padding: 12px 16px; border-radius: 4px; margin: 16px 0;">
<strong>Note:</strong> %s
</p>
<p>All of your previous posts and comments have been restored and are visible again. Please review our <a href="https://sojorn.net/terms" style="color: #4338CA;">Community Guidelines</a> to ensure continued access to the platform.</p>
`, toName, reason)
footer := ``
htmlBody := s.buildHTMLEmail(title, header, content, "https://sojorn.net", "Open Sojorn", footer)
textBody := fmt.Sprintf("Hi %s,\n\nYour Sojorn account has been restored and is fully active again.\n\nNote: %s\n\nAll of your posts and comments are visible again.\n\n— The Sojorn Team", toName, reason)
return s.sendEmail(toEmail, toName, subject, htmlBody, textBody)
}
func (s *EmailService) AddSubscriber(email, name string) {
// SendPulse Addressbook API implementation omitted for brevity, focusing on email first
// Endpoint: POST /addressbooks/{id}/emails