Viewing:
package h import ( "bytes" "html/template" "io" "log/slog" "strings" "gopkg.awl.red/bizdex/config" ) var templateLogin = template.Must(template.New("template_login").Parse(`<!doctype html> <html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> {{.StyleTag}} </head><body> <title>Login</title> <h1>{{ .Config.Title }} Login</h1> <form method="post" action="/login"> <div> <label for="email">Email: </label> <input id="email" name="email" type="text" autocomplete="on"></input> </div> <div> <label for="username">Username: </label> <input id="username" name="username" type="text" autocomplete="on"></input> </div> <div> <label for="password">Password: </label> <input id="password" name="password" type="password" {{ if .Config.PasswordRequired }}required{{ end }} ></input> </div> <div> <input id="submit" name="submit" type="submit" value="Log in"></input> </div> </form> </body></html> `)) var templateAbout = template.Must(template.New("template_about").Parse(`<!doctype html> <html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> {{.StyleTag}} </head><body> <title>About {{.Data.title}}</title> <h1>About {{.Data.title}}</h1> {{ range .Data.about_p }} {{ if ne . "" }}<p>{{.}}</p>{{ end }} {{ end }} {{ if .Data.has_support }} <h2>Support</h2> <p>If you need support as a user of this site, you can reach out to:<p> <ul> {{ if ne .Data.support_email "" }} <li>email: {{.Data.support_email}}</li> {{ end }} {{ if ne .Data.support_phone "" }} <li>phone: {{.Data.support_phone}}</li> {{ end }} </ul> {{ end }} {{ if gt (len (index .Data.disclaimer_p 0)) 0}} <h2>Disclaimer</h2> {{ end }} {{ range .Data.disclaimer_p }} <p>{{.}}</p> {{ end }} </body></html> `)) var templateSignup = template.Must(template.New("template_signup").Parse(`<!doctype html> <html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> {{.StyleTag}} </head><body> <title>Signup</title> <h1>{{ .Config.Title }} Account Signup</h1> <form method="post" action="/signup"> <div> <label for="username">Username: </label> <input id="username" name="username" type="text" autocomplete="on"></input> </div> <div> <label for="firstname">First name: </label> <input id="firstname" name="firstname" type="firstname" autocomplete="on"></input> </div> <div> <label for="lastname">Last name: </label> <input id="lastname" name="lastname" type="lastname" autocomplete="on"></input> </div> <div> <label for="password">Password: </label> <input id="password" name="password" type="password" {{ if .Config.PasswordRequired }}required{{ end }} {{ if .Config.PasswordMin }}minlength="{{ .Config.PasswordMin }}"{{ end }} ></input> </div> <div> <label for="password_confirm">Password Confirm: </label> <input id="password_confirm" name="password_confirm" type="password" {{ if .Config.PasswordRequired }}required{{ end }} {{ if .Config.PasswordMin }}minlength="{{ .Config.PasswordMin }}"{{ end }} ></input> </div> <div> <label for="email">Email: </label> <input id="email" name="email" type="text" {{ if .Config.EmailRequired }}required{{ end }} autocomplete="on"></input> </div> {{ if .Config.SignupNeedsApprove }} <div style="padding-bottom:0;"> <label for="request_text">(Optional): Account Purpose</label> <textarea id="request_text" name="request_text" maxlength="255" style="resize:vertical; max-height:400px; min-height: 60px;"></textarea> </div> <p style='margin: 0; font-style: italic; padding-top: 10px;padding-bottom: 20px;'>You can include a short note to the admin about who you are, why you want to sign up, and what service(s) you are providing to which locale(s). If you are reaching out to the admin separately or the admin is already waiting for your signup, this may not be necessary.</p> {{ end }} <div> <input id="submit" name="submit" type="submit"></input> </div> </form> </body></html> `)) type ConfigTemplateData struct { Config *config.Config `json:"config"` Data any `json:"data"` StyleTag template.HTML `json:"style_tag"` } func TLogin(w io.Writer, c *config.Config) error { var stylesheetBuf bytes.Buffer templateBaseStylesheet.Execute(&stylesheetBuf, ConfigTemplateData{Config: c}) return templateLogin.Execute(w, ConfigTemplateData{Config: c, StyleTag: template.HTML(stylesheetBuf.String())}) } func TSignup(w io.Writer, c *config.Config) error { var stylesheetBuf bytes.Buffer templateBaseStylesheet.Execute(&stylesheetBuf, ConfigTemplateData{Config: c}) return templateSignup.Execute(w, ConfigTemplateData{Config: c, StyleTag: template.HTML(stylesheetBuf.String())}) } func TAbout(w io.Writer, c *config.Config) error { var stylesheetBuf bytes.Buffer templateBaseStylesheet.Execute(&stylesheetBuf, ConfigTemplateData{Config: c}) slog.Info("adf", "ph", c.SupportPhone, "em", c.SupportEmail) return templateAbout.Execute(w, ConfigTemplateData{ Config: c, StyleTag: template.HTML(stylesheetBuf.String()), Data: map[string]any{ "title": c.Title, "support_email": c.SupportEmail, "support_phone": c.SupportPhone, "has_support": c.SupportEmail+c.SupportPhone != "", "about_p": strings.Split(c.Purpose, "\\n"), "disclaimer_p": strings.Split(c.Disclaimer, "\\n"), }}) }