2023-09-26 20:36:03 +00:00
|
|
|
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 {
|
2023-10-09 15:46:36 +00:00
|
|
|
c.Templates.TwoFA = r
|
2023-09-26 20:36:03 +00:00
|
|
|
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())
|
|
|
|
}
|
2023-10-09 15:46:36 +00:00
|
|
|
c.Templates.TwoFA = r
|
2023-09-26 20:36:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|