package scsusers import ( "embed" "html/template" "log" ) //go:embed templates/*.html var FS embed.FS func SetRegistrationTemplate(t string) bool { if len(t) != 0 { r, err := template.New("reg").Parse(t) if err != nil { c.Templates.Registration = r return true } } df, err := FS.ReadFile("templates/registration.html") if err != nil { log.Fatal("Missing recovery template") } r, err := template.New("reg").Parse(string(df)) if err != nil { log.Fatal("scsusers.SetRegistrationTemplate: Default registration template MUST compile. Error: " + err.Error()) } c.Templates.Registration = r return false } func Set2faTemplate(t string) bool { if len(t) != 0 { r, err := template.New("2fa").Parse(t) if err != nil { c.Templates.TwoFA = r return true } } df, err := FS.ReadFile("templates/2fa.html") if err != nil { log.Fatal("Missing 2fa template") } r, err := template.New("2fa").Parse(string(df)) if err != nil { log.Fatal("scsusers.Set2faTemplate: Default 2fa template MUST compile. Error: " + err.Error()) } c.Templates.TwoFA = r return false } func SetAlertTemplate(t string) bool { if len(t) != 0 { r, err := template.New("alert").Parse(t) if err != nil { c.Templates.Alert = r return true } } df, err := FS.ReadFile("templates/alert.html") if err != nil { log.Fatal("Missing recovery template") } r, err := template.New("alert").Parse(string(df)) if err != nil { log.Fatal("scsusers.SetAlertTemplate: Default alert template MUST compile. Error: " + err.Error()) } c.Templates.Alert = r return false } func SetRecoveryTemplate(t string) bool { if len(t) != 0 { r, err := template.New("recovery").Parse(t) if err != nil { c.Templates.Recovery = r return true } } df, err := FS.ReadFile("templates/recovery.html") if err != nil { log.Fatal("Missing recovery template") } r, err := template.New("recovery").Parse(string(df)) if err != nil { log.Fatal("scsusers.SetRecoveryTemplate: Default recovery template MUST compile. Error: " + err.Error()) } c.Templates.Recovery = r return false }