00f6b51228
Implemented email service infrastructure with SMTP support and optional email verification for self-hosted deployments. Registration flow now supports open/closed modes and hardcoded Apocapoc branding. Key features: - Email service with SMTP and template rendering - Optional email verification (auto-verified without SMTP config) - Registration modes: open/closed for access control - Hardcoded Apocapoc branding (AppName, AppURL, DefaultFrom) - Separate registration and login flows (registration no longer returns tokens)
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package email
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"html/template"
|
|
)
|
|
|
|
type TemplateData struct {
|
|
AppName string
|
|
AppURL string
|
|
SupportEmail string
|
|
Data map[string]interface{}
|
|
}
|
|
|
|
type TemplateRenderer struct {
|
|
appName string
|
|
appURL string
|
|
supportEmail string
|
|
}
|
|
|
|
func NewTemplateRenderer(appName, appURL, supportEmail string) *TemplateRenderer {
|
|
return &TemplateRenderer{
|
|
appName: appName,
|
|
appURL: appURL,
|
|
supportEmail: supportEmail,
|
|
}
|
|
}
|
|
|
|
func (r *TemplateRenderer) Render(templateContent string, data map[string]interface{}) (string, error) {
|
|
tmpl, err := template.New("email").Parse(templateContent)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to parse template: %w", err)
|
|
}
|
|
|
|
templateData := TemplateData{
|
|
AppName: r.appName,
|
|
AppURL: r.appURL,
|
|
SupportEmail: r.supportEmail,
|
|
Data: data,
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
if err := tmpl.Execute(&buf, templateData); err != nil {
|
|
return "", fmt.Errorf("failed to execute template: %w", err)
|
|
}
|
|
|
|
return buf.String(), nil
|
|
}
|