diff options
Diffstat (limited to 'internal/email')
-rw-r--r-- | internal/email/email_test.go | 8 | ||||
-rw-r--r-- | internal/email/noopsender.go | 8 | ||||
-rw-r--r-- | internal/email/sender.go | 8 | ||||
-rw-r--r-- | internal/email/signup.go | 36 |
4 files changed, 56 insertions, 4 deletions
diff --git a/internal/email/email_test.go b/internal/email/email_test.go index 34d0d1c2f..b57562cb5 100644 --- a/internal/email/email_test.go +++ b/internal/email/email_test.go @@ -50,7 +50,7 @@ func (suite *EmailTestSuite) TestTemplateConfirm() { suite.sender.SendConfirmEmail("user@example.org", confirmData) suite.Len(suite.sentEmails, 1) - suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Email Confirmation\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello test!\r\n\r\nYou are receiving this mail because you've requested an account on https://example.org.\r\n\r\nTo use your account, you must confirm that this is your email address.\r\n\r\nTo confirm your email, paste the following in your browser's address bar:\r\n\r\nhttps://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"]) + suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Email Confirmation\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello test!\r\n\r\nYou are receiving this mail because you've requested an account on https://example.org.\r\n\r\nTo use your account, you must confirm that this is your email address.\r\n\r\nTo confirm your email, paste the following in your browser's address bar:\r\n\r\nhttps://example.org/confirm_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\r\n\r\n---\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"]) } func (suite *EmailTestSuite) TestTemplateReset() { @@ -63,7 +63,7 @@ func (suite *EmailTestSuite) TestTemplateReset() { suite.sender.SendResetEmail("user@example.org", resetData) suite.Len(suite.sentEmails, 1) - suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Password Reset\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello test!\r\n\r\nYou are receiving this mail because a password reset has been requested for your account on https://example.org.\r\n\r\nTo reset your password, paste the following in your browser's address bar:\r\n\r\nhttps://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"]) + suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Password Reset\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello test!\r\n\r\nYou are receiving this mail because a password reset has been requested for your account on https://example.org.\r\n\r\nTo reset your password, paste the following in your browser's address bar:\r\n\r\nhttps://example.org/reset_email?token=ee24f71d-e615-43f9-afae-385c0799b7fa\r\n\r\n---\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"]) } func (suite *EmailTestSuite) TestTemplateReportRemoteToLocal() { @@ -166,7 +166,7 @@ func (suite *EmailTestSuite) TestTemplateReportClosedOK() { suite.FailNow(err.Error()) } suite.Len(suite.sentEmails, 1) - suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Report Closed\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello !\r\n\r\nYou recently reported the account @foss_satan@fossbros-anonymous.io to the moderator(s) of Test Instance (https://example.org).\r\n\r\nThe report you submitted has now been closed.\r\n\r\nThe moderator who closed the report left the following comment: User was yeeted. Thank you for reporting!\r\n\r\n", suite.sentEmails["user@example.org"]) + suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Report Closed\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello !\r\n\r\nYou recently reported the account @foss_satan@fossbros-anonymous.io to the moderator(s) of Test Instance (https://example.org).\r\n\r\nThe report you submitted has now been closed.\r\n\r\nThe moderator who closed the report left the following comment: User was yeeted. Thank you for reporting!\r\n\r\n---\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"]) } func (suite *EmailTestSuite) TestTemplateReportClosedLocalAccountNoComment() { @@ -182,7 +182,7 @@ func (suite *EmailTestSuite) TestTemplateReportClosedLocalAccountNoComment() { suite.FailNow(err.Error()) } suite.Len(suite.sentEmails, 1) - suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Report Closed\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello !\r\n\r\nYou recently reported the account @1happyturtle to the moderator(s) of Test Instance (https://example.org).\r\n\r\nThe report you submitted has now been closed.\r\n\r\nThe moderator who closed the report did not leave a comment.\r\n\r\n", suite.sentEmails["user@example.org"]) + suite.Equal("To: user@example.org\r\nFrom: test@example.org\r\nSubject: GoToSocial Report Closed\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"\r\n\r\nHello !\r\n\r\nYou recently reported the account @1happyturtle to the moderator(s) of Test Instance (https://example.org).\r\n\r\nThe report you submitted has now been closed.\r\n\r\nThe moderator who closed the report did not leave a comment.\r\n\r\n---\r\n\r\nIf you believe you've been sent this email in error, feel free to ignore it, or contact the administrator of https://example.org.\r\n\r\n", suite.sentEmails["user@example.org"]) } func TestEmailTestSuite(t *testing.T) { diff --git a/internal/email/noopsender.go b/internal/email/noopsender.go index 44aa86dba..20d7df2eb 100644 --- a/internal/email/noopsender.go +++ b/internal/email/noopsender.go @@ -72,6 +72,14 @@ func (s *noopSender) SendNewSignupEmail(toAddresses []string, data NewSignupData return s.sendTemplate(newSignupTemplate, newSignupSubject, data, toAddresses...) } +func (s *noopSender) SendSignupApprovedEmail(toAddress string, data SignupApprovedData) error { + return s.sendTemplate(signupApprovedTemplate, signupApprovedSubject, data, toAddress) +} + +func (s *noopSender) SendSignupRejectedEmail(toAddress string, data SignupRejectedData) error { + return s.sendTemplate(signupRejectedTemplate, signupRejectedSubject, data, toAddress) +} + func (s *noopSender) sendTemplate(template string, subject string, data any, toAddresses ...string) error { buf := &bytes.Buffer{} if err := s.template.ExecuteTemplate(buf, template, data); err != nil { diff --git a/internal/email/sender.go b/internal/email/sender.go index 78338a0dd..a3efa6124 100644 --- a/internal/email/sender.go +++ b/internal/email/sender.go @@ -53,6 +53,14 @@ type Sender interface { // It is expected that the toAddresses have already been filtered to ensure // that they all belong to active admins + moderators. SendNewSignupEmail(toAddress []string, data NewSignupData) error + + // SendSignupApprovedEmail sends an email to the given address + // that their sign-up request has been approved by a moderator. + SendSignupApprovedEmail(toAddress string, data SignupApprovedData) error + + // SendSignupRejectedEmail sends an email to the given address + // that their sign-up request has been rejected by a moderator. + SendSignupRejectedEmail(toAddress string, data SignupRejectedData) error } // NewSender returns a new email Sender interface with the given configuration, or an error if something goes wrong. diff --git a/internal/email/signup.go b/internal/email/signup.go index 84162c21e..2eaffc8a9 100644 --- a/internal/email/signup.go +++ b/internal/email/signup.go @@ -40,3 +40,39 @@ type NewSignupData struct { func (s *sender) SendNewSignupEmail(toAddresses []string, data NewSignupData) error { return s.sendTemplate(newSignupTemplate, newSignupSubject, data, toAddresses...) } + +var ( + signupApprovedTemplate = "email_signup_approved.tmpl" + signupApprovedSubject = "GoToSocial Sign-Up Approved" +) + +type SignupApprovedData struct { + // Username to be addressed. + Username string + // URL of the instance to present to the receiver. + InstanceURL string + // Name of the instance to present to the receiver. + InstanceName string +} + +func (s *sender) SendSignupApprovedEmail(toAddress string, data SignupApprovedData) error { + return s.sendTemplate(signupApprovedTemplate, signupApprovedSubject, data, toAddress) +} + +var ( + signupRejectedTemplate = "email_signup_rejected.tmpl" + signupRejectedSubject = "GoToSocial Sign-Up Rejected" +) + +type SignupRejectedData struct { + // Message to the rejected applicant. + Message string + // URL of the instance to present to the receiver. + InstanceURL string + // Name of the instance to present to the receiver. + InstanceName string +} + +func (s *sender) SendSignupRejectedEmail(toAddress string, data SignupRejectedData) error { + return s.sendTemplate(signupRejectedTemplate, signupRejectedSubject, data, toAddress) +} |