templates

package
v0.0.0-...-a58f080 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OTPTemplate = Template{
	ID: "otp",
	Email: func(data TemplateData) (EmailTemplateData, error) {
		otpData, ok := data.(*OTPTemplateData)
		if !ok {
			return EmailTemplateData{}, fmt.Errorf("invalid template data type")
		}

		return EmailTemplateData{
			Name:    otpData.Name,
			Subject: "Your verification code",
			Actions: []hermes.Action{
				{
					Instructions: "Please use the following code to verify your account:",
					InviteCode:   otpData.OTP,
				},
			},
			Outros: []string{
				"If you did not request this code, please ignore this email.",
			},
		}, nil
	},
	SMS: func(data TemplateData) (SMSTemplateData, error) {
		otpData, ok := data.(*OTPTemplateData)
		if !ok {
			return SMSTemplateData{}, fmt.Errorf("invalid template data type")
		}

		return SMSTemplateData{
			Message: fmt.Sprintf("Your verification code is: %s. Don't share this code with anyone.", otpData.OTP),
		}, nil
	},
}
View Source
var ResetPasswordTemplate = Template{
	ID: "reset_password",
	Email: func(data TemplateData) (EmailTemplateData, error) {
		resetData, ok := data.(*ResetPasswordTemplateData)
		if !ok {
			return EmailTemplateData{}, fmt.Errorf("invalid template data type")
		}

		return EmailTemplateData{
			Subject: "Reset Your Password",
			Name:    resetData.Name,
			Actions: []hermes.Action{
				{
					Instructions: "Click the button below to reset your password:",
					Button: hermes.Button{
						Text: "Reset Password",
						Link: fmt.Sprintf("%s/reset-password/verify?code=%s&email=%s", config.GetURL(), resetData.ResetCode, resetData.Email),
					},
				},
			},
			Outros: []string{
				"If you did not request a password reset, please ignore this email.",
			},
		}, nil
	},
	SMS: func(data TemplateData) (SMSTemplateData, error) {
		return SMSTemplateData{}, fmt.Errorf("sms notifications not supported for password reset")
	},
}
View Source
var Templates = map[string]Template{
	"otp":            OTPTemplate,
	"reset_password": ResetPasswordTemplate,
}

Functions

This section is empty.

Types

type EmailTemplateData

type EmailTemplateData struct {
	Subject string
	Body    string
	Intros  []string
	Actions []hermes.Action
	Outros  []string
	Name    string
}

type OTPTemplateData

type OTPTemplateData struct {
	OTP  string
	Name string
}

OTPTemplateData is a specific template data type for OTP notifications

func (*OTPTemplateData) Validate

func (d *OTPTemplateData) Validate() error

Validate implements TemplateData interface for OTPTemplateData

type ResetPasswordTemplateData

type ResetPasswordTemplateData struct {
	ResetCode string
	Email     string
	Name      string
}

ResetPasswordTemplateData is a specific template data type for password reset notifications

func (*ResetPasswordTemplateData) Validate

func (d *ResetPasswordTemplateData) Validate() error

Validate implements TemplateData interface for ResetPasswordTemplateData

type SMSTemplateData

type SMSTemplateData struct {
	Message string
}

type Template

type Template struct {
	ID    string
	Email func(data TemplateData) (EmailTemplateData, error)
	SMS   func(data TemplateData) (SMSTemplateData, error)
}

Template defines content for each supported channel

type TemplateData

type TemplateData interface {
	Validate() error
}

TemplateData is the interface that all template data must implement

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址