hlfw.ca

webbing

Download patch

ref: 248053a1e06496381243c8795ecc3ae556269776
parent: a4b7cba24cc786a44f5ccb4720f802140632d580
author: Halfwit <halfwit@MacBook-Pro.hitronhub.home>
date: Thu Dec 12 11:35:40 PST 2019

Move errors out to templates/plugin

--- a/email/signup.go
+++ b/email/signup.go
@@ -14,7 +14,7 @@
 )
 
 // TODO(halfwit) Update with whichever TLD we land on
-var url = "https://olmaxmedical.com"
+var url = "https://medical.olmax.dev"
 
 // SendSignup - email our prospective clients and create tokens
 func SendSignup(first, last, email, pass string, p *message.Printer) {
--- a/router/forms.go
+++ b/router/forms.go
@@ -40,7 +40,6 @@
 	for _, key := range pluginKey {
 		if (form.After&key) != 0 && pluginCache[key].Validate != nil {
 			if e := pluginCache[key].Validate(p); e != nil {
-				fmt.Fprintf(w, "%q\n", e)
 				errors = append(errors, fmt.Sprint(e))
 				return nil, errors
 			}
--- a/router/pages.go
+++ b/router/pages.go
@@ -52,7 +52,6 @@
 	var errs []error
 	hd := path.Join("templates", "header.tpl")
 	fd := path.Join("templates", "footer.tpl")
-	ed := path.Join("templates", "errors.tpl")
 	ld := path.Join("templates", "layout.tpl")
 	extra, err := os.Open(path.Join("templates", "plugins"))
 	if err != nil {
@@ -64,7 +63,7 @@
 		dirs[n] = path.Join("templates", "plugins", dir)
 	}
 	// TODO(halfwit) Validate our plugin templates here as well
-	dirs = append(dirs, hd, fd, ed, ld)
+	dirs = append(dirs, hd, fd, ld)
 	printer := message.NewPrinter(message.MatchLanguage("en"))
 	for _, item := range pagecache {
 		var err error
--- a/router/run.go
+++ b/router/run.go
@@ -131,6 +131,7 @@
 		// NOTE(halfwit) this stashes previous entries, but does not work
 		// on multipart forms (with file uploads)
 		us.Set("errors", errors)
+		// Maybe store form args instead here in session
 		url := fmt.Sprintf("%s?%s", r.URL.String(), r.Form.Encode())
 		http.Redirect(w, r, url, 302)
 	}
--- a/templates/doctor/application.tpl
+++ b/templates/doctor/application.tpl
@@ -1,6 +1,6 @@
 {{define "content"}}
 	<main>
-	        {{template "errors" .errors}}
+	    {{template "errors" .errors}}
 		<label for="application">{{.offer}}</label>
 		<form id="application" method="post" enctype="multipart/form-data" boundary="VAL">
 			<h4>{{.area}}</h4>
--- a/templates/errors.tpl
+++ /dev/null
@@ -1,5 +1,0 @@
-{{define "errors"}}
-	      {{range .}}
-	      <p style="color: red" class="errtext">{{.}}</p>
-	      {{end}}
-{{end}}
\ No newline at end of file
--- a/templates/login.tpl
+++ b/templates/login.tpl
@@ -1,9 +1,7 @@
 {{define "content"}}
 	<main>
             <h3>{{if .redirect }}{{.continue}}{{else}}{{.greeting}}{{end}}</h3>
-	      {{range .errors}}
-	      <p style="color: red" class="errtext">{{.}}</p>
-	      {{end}}
+	      {{template "errors" .errors}}
 	      <form method="post" action="login.html">
 			<label for="email">{{.email}}*</label>
 			<input type="email" name="email" id="email" required autocomplete="off"/><br>
--- a/templates/newpassword.tpl
+++ b/templates/newpassword.tpl
@@ -1,10 +1,9 @@
 {{define "content"}}
 	<main>
-            <h3>{{.reset}}</h3>
-	      {{range .errors}}
-	      <p style="color: red" class="errtext">{{.}}</p>
-	      {{end}}
-	      <form method="post" action="{{.basedir}}/newpassword.html">
+        <h3>{{.reset}}</h3>
+		
+		{{template "errors" .errors}}
+	    <form method="post" action="{{.basedir}}/newpassword.html">
 			<input type="hidden" name="token" value="{{.token}}"/>
 			<label for="password">{{.password}}*</label>
 			<input type="password" name="password" id="password" required autocomplete="off"/><br>
@@ -11,6 +10,6 @@
 			<laber for="reenter">{{.reenter}}*</label>
 			<input type="password" name="reenter" id="reenter" required autocomplete="off"/><br>
 			<button type="submit" class="button button-block"/>{{.update}}</button>
-          </form>
+        </form>
 	</main>
 {{end}}
\ No newline at end of file
--- a/templates/resetpassword.tpl
+++ b/templates/resetpassword.tpl
@@ -1,9 +1,7 @@
 {{define "content"}}
 	<main>
             <h3>{{.reset}}</h3>
-	      {{range .errors}}
-	      <p style="color: red" class="errtext">{{.}}</p>
-	      {{end}}
+	      {{template "errors" .errors}}
 	      <p>{{.resettext}}
 	      <form method="post" action="resetpassword.html">
 			<label for="email">{{.email}}*</label>
--- a/templates/signup.tpl
+++ b/templates/signup.tpl
@@ -1,9 +1,7 @@
 {{define "content"}}
 	<main>
 		<h2>{{.mainHeader}}</h2>
-		{{range .errors}}
-		<p style="color: red" class="errtext">{{.}}</p>
-	        {{end}}
+		{{template "errors" .errors}}
 		<form method="post" action="signup.html">
 			<label for="fname">{{.fname}}*</label>
 			<input type="text" name="fname" id="fname" placeholder="{{.fnameph}}" required autocomplete="off" autofocus/><br>