diff --git a/go-backend/internal/handlers/admin_handler.go b/go-backend/internal/handlers/admin_handler.go index f657dd8..2b11b34 100644 --- a/go-backend/internal/handlers/admin_handler.go +++ b/go-backend/internal/handlers/admin_handler.go @@ -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") + } + } } }() } diff --git a/go-backend/internal/services/email_service.go b/go-backend/internal/services/email_service.go index d8270e6..18b01ab 100644 --- a/go-backend/internal/services/email_service.go +++ b/go-backend/internal/services/email_service.go @@ -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(` +
Hi %s,
+Great news ā your Sojorn account has been restored and is fully active again.
++ Note: %s +
+All of your previous posts and comments have been restored and are visible again. Please review our Community Guidelines to ensure continued access to the platform.
+ `, 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