diff --git a/src/email/email.go b/src/email/email.go index 918a5899..7021f898 100644 --- a/src/email/email.go +++ b/src/email/email.go @@ -91,6 +91,41 @@ func SendPasswordReset(toAddress string, toName string, username string, resetTo return nil } +type TimeMachineEmailData struct { + ProfileUrl string + Username string + UserEmail string + DiscordUsername string + MediaUrl string + DeviceInfo string + Description string +} + +func SendTimeMachineEmail(profileUrl, username, userEmail, discordUsername, mediaUrl, deviceInfo, description string, perf *perf.RequestPerf) error { + perf.StartBlock("EMAIL", "Time machine email") + defer perf.EndBlock() + + contents, err := renderTemplate("email_time_machine.html", TimeMachineEmailData{ + ProfileUrl: profileUrl, + Username: username, + UserEmail: userEmail, + DiscordUsername: discordUsername, + MediaUrl: mediaUrl, + DeviceInfo: deviceInfo, + Description: description, + }) + if err != nil { + return err + } + + err = sendMail("team@handmade.network", "HMN Team", "[time machine] New submission", contents) + if err != nil { + return oops.New(err, "Failed to send email") + } + + return nil +} + var EmailRegex = regexp.MustCompile(`^[^:\p{Cc} ]+@[^:\p{Cc} ]+\.[^:\p{Cc} ]+$`) func IsEmail(address string) bool { diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index b2691e5a..9a7cbd17 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -112,6 +112,20 @@ func BuildTimeMachine() string { return Url("/timemachine", nil) } +var RegexTimeMachineForm = regexp.MustCompile("^/timemachine/submit$") + +func BuildTimeMachineForm() string { + defer CatchPanic() + return Url("/timemachine/submit", nil) +} + +var RegexTimeMachineFormDone = regexp.MustCompile("^/timemachine/thanks$") + +func BuildTimeMachineFormDone() string { + defer CatchPanic() + return Url("/timemachine/thanks", nil) +} + // QUESTION(ben): Can we change these routes? var RegexLoginAction = regexp.MustCompile("^/login$") diff --git a/src/templates/src/email_time_machine.html b/src/templates/src/email_time_machine.html new file mode 100644 index 00000000..6bd6e08f --- /dev/null +++ b/src/templates/src/email_time_machine.html @@ -0,0 +1,6 @@ +
Submission by {{ .Username }} ({{ .UserEmail }}) {{ if .DiscordUsername }} On Discord: {{ .DiscordUsername }} {{ end }}
+Submitted url: {{ .MediaUrl }}
+Device info:{{ .DeviceInfo }}+Description:
{{ .Description }}diff --git a/src/templates/src/layouts/timemachine_base.html b/src/templates/src/layouts/timemachine_base.html index 68a0cacd..33509694 100644 --- a/src/templates/src/layouts/timemachine_base.html +++ b/src/templates/src/layouts/timemachine_base.html @@ -33,6 +33,127 @@ + + diff --git a/src/templates/src/time-machine.html b/src/templates/src/time-machine.html index 4ca5f8ba..635fbea5 100644 --- a/src/templates/src/time-machine.html +++ b/src/templates/src/time-machine.html @@ -8,126 +8,6 @@ {{ end }} {{ define "content" }} -