diff --git a/src/email/email.go b/src/email/email.go index 5a71a2de..7d1ba631 100644 --- a/src/email/email.go +++ b/src/email/email.go @@ -48,7 +48,47 @@ func SendRegistrationEmail( perf.EndBlock() perf.StartBlock("EMAIL", "Sending email") - err = sendMail(toAddress, toName, "[handmade.network] Registration confirmation", contents) + err = sendMail(toAddress, toName, "[Handmade Network] Registration confirmation", contents) + if err != nil { + return oops.New(err, "Failed to send email") + } + perf.EndBlock() + + perf.EndBlock() + + return nil +} + +type ExistingAccountEmailData struct { + Name string + Username string + HomepageUrl string + LoginUrl string +} + +func SendExistingAccountEmail( + toAddress string, + toName string, + username string, + destination string, + perf *perf.RequestPerf, +) error { + perf.StartBlock("EMAIL", "Existing account email") + + perf.StartBlock("EMAIL", "Rendering template") + contents, err := renderTemplate("email_account_existing.html", ExistingAccountEmailData{ + Name: toName, + Username: username, + HomepageUrl: hmnurl.BuildHomepage(), + LoginUrl: hmnurl.BuildLoginPage(destination), + }) + if err != nil { + return err + } + perf.EndBlock() + + perf.StartBlock("EMAIL", "Sending email") + err = sendMail(toAddress, toName, "[Handmade Network] You already have an account!", contents) if err != nil { return oops.New(err, "Failed to send email") } @@ -80,7 +120,7 @@ func SendPasswordReset(toAddress string, toName string, username string, resetTo perf.EndBlock() perf.StartBlock("EMAIL", "Sending email") - err = sendMail(toAddress, toName, "[handmade.network] Your password reset request", contents) + err = sendMail(toAddress, toName, "[Handmade Network] Your password reset request", contents) if err != nil { return oops.New(err, "Failed to send email") } @@ -118,7 +158,7 @@ func SendTimeMachineEmail(profileUrl, username, userEmail, discordUsername strin return err } - err = sendMail("team@handmade.network", "HMN Team", "[time machine] New submission", contents) + err = sendMail("team@handmade.network", "HMN Team", "[Time Machine] New submission", contents) if err != nil { return oops.New(err, "Failed to send email") } diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index f1527223..04801585 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -165,7 +165,11 @@ var RegexLoginPage = regexp.MustCompile("^/login$") func BuildLoginPage(redirectTo string) string { defer CatchPanic() - return Url("/login", []Q{{Name: "redirect", Value: redirectTo}}) + var q []Q + if redirectTo != "" { + q = append(q, Q{Name: "redirect", Value: redirectTo}) + } + return Url("/login", q) } var RegexLoginWithDiscord = regexp.MustCompile("^/login-with-discord$") diff --git a/src/templates/src/email_account_existing.html b/src/templates/src/email_account_existing.html new file mode 100644 index 00000000..b61d9b81 --- /dev/null +++ b/src/templates/src/email_account_existing.html @@ -0,0 +1,16 @@ +
+ Hello {{ .Name }} - you already have a Handmade Network account. Welcome back! +
++ Your username is {{ .Username }}. To sign in, please visit the following link and try signing in with your existing username: +
++ {{ .LoginUrl }} +
+Thanks,
+The Handmade Network staff.
+You are receiving this email because someone tried creating a new account with your email address at handmade.network. If that wasn't you, kindly ignore this email. +
diff --git a/src/templates/src/email_registration.html b/src/templates/src/email_registration.html index 7e82a964..74954222 100644 --- a/src/templates/src/email_registration.html +++ b/src/templates/src/email_registration.html @@ -5,7 +5,7 @@ To complete the registration process, please use the following link:- {{ .CompleteRegistrationUrl }}. + {{ .CompleteRegistrationUrl }}
Thanks,
The Handmade Network staff.