package templates import ( "prosocial/database" "time" _ "time/tzdata" "github.com/rs/zerolog/log" "github.com/google/uuid" ) type Template interface { TemplatePath() string // path to the template stored in the server OnClickPath() string // every notification needs to be clickable, and that should take the user somewhere. // leave blank to mark as read?? } type welcome struct { UserID uuid.UUID FirstName string LastName string Date time.Time } func Welcome(userId uuid.UUID, firstName string, lastName string) welcome { return welcome{ UserID: userId, FirstName: firstName, LastName: lastName, Date: time.Now().UTC().Local(), } } func (m welcome) TemplatePath() string { return "templates/web/welcome.tmpl" } func (m welcome) OnClickPath() string { return "/" } type verificationEmail struct { email string Recipient string VerificationCode string Date string OperatingSystem string Browser string Location string } type passwordResetEmail struct { email string Recipient string ResetLink string Date string OperatingSystem string Browser string Location string } func NewVerificationEmail(recipient, verificationCode, operatingSystem, browser string) verificationEmail { return verificationEmail{ email: recipient, Recipient: getNameByEmail(recipient), VerificationCode: verificationCode, Date: time.Now().Format("2006-01-02 15:04"), OperatingSystem: operatingSystem, Browser: browser, } } func NewPasswordResetEmail(recipient, passwordResetLink, operatingSystem, browser string) passwordResetEmail { return passwordResetEmail{ email: recipient, Recipient: getNameByEmail(recipient), ResetLink: passwordResetLink, Date: time.Now().Format("2006-01-02 15:04"), OperatingSystem: operatingSystem, Browser: browser, } } func (m verificationEmail) TemplatePath() string { return "templates/email/verification-code.tmpl" } func (m verificationEmail) OnClickPath() string { return "" } func (m passwordResetEmail) TemplatePath() string { return "templates/email/password-reset-token.tmpl" } func getNameByEmail(email string) string { user, err := database.GetUserByEmail(email) if err != nil { log.Debug().Err(err) return "Failed to retrieve user." } return user.Name }