hlfw.ca

webbing

Download patch

ref: 350c01ad73bd4d71473a3f1b1b281e800127939c
parent: 25353fa9605f9291ba526ad43cec0c074c9e7786
author: Halfwit <halfwit@MacBook-Pro.hitronhub.home>
date: Thu Dec 12 10:15:06 PST 2019

Add arbitrary templates relating to plugins

--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 client
 vscode.code-workspace
 .DS_Store
+work.code-workspace
--- a/TODO
+++ b/TODO
@@ -40,7 +40,7 @@
 [ ] plugins/bookings.go: URL encodidng such as '?id=1320984392184298'
 [ ] plugins/bookings.go: Use token to add booking data to map
 [ ] pages/doctor/bookings.go: Boiler plate internationalization
-[ ] templates/doctor/bookings.tpl: convert from doctor/bookings.html
+[ ] templates/doctor/bookings.tpl: create table for data coming back from bookings (nest template) 
 
 TODO (halfwit) doctor/profile.html - List bookings, messages
 [ ] plugins/messages.go: Use User ID to fetch list of messages
@@ -62,7 +62,7 @@
 [ ] plugins/appointments.go: URL encoding such as '?id=21092198409'
 [ ] plugins/appointments.go: Use token to add booking data to map
 [ ] pages/patient/appointment.go: Boiler plate internationalization
-[ ] templates/patient/appointment.tpl: convert from patient/appointment.html
+[ ] templates/patient/appointment.tpl: create table for listing appointments (nest template)
 
 TODO (halfwit) patient/offer.html - Create an offer to book time with a doctor
 [ ] plugins/offer.go: URL encoding such as '?id=1298749827'
@@ -94,4 +94,6 @@
 
 TODO (halfwit) - TLS + SSL certs for the whole site
 [x] Create local certs for testing
-[x] Move to tls functions - commented out for now
\ No newline at end of file
+[x] Move to tls functions - commented out for now
+[ ] Purchase cert from CA
+[ ] Sign and use for site
--- a/pages/doctor/profile.go
+++ b/pages/doctor/profile.go
@@ -12,7 +12,7 @@
 		CSS:    "",
 		Path:   "doctor/profile",
 		Data:   profile,
-		Extra:  plugins.FormErrors | plugins.FormToken,
+		Extra:  plugins.FormErrors | plugins.FormToken | plugins.ListBookings,
 	}
 	router.AddPage(b)
 }
--- /dev/null
+++ b/plugins/bookings.go
@@ -1,0 +1,22 @@
+package plugins
+
+import (
+	"github.com/olmaxmedical/olmax_go/router"
+)
+
+// ListBookings retreives a list of all upcoming bookings for a given doctor
+const ListBookings router.PluginMask = 1 << 13
+
+func init() {
+	b := &router.Plugin{
+		Name:     "List Bookings",
+		Run:      nil,
+		Validate: listBookings,
+	}
+	router.AddPlugin(b, ListBookings)
+}
+
+func listBookings(s *router.Request) error {
+	
+	return nil
+}
--- a/router/cert.go
+++ b/router/cert.go
@@ -1,44 +1,21 @@
 package router
 
 import (
-    "crypto/tls"
-    "crypto/x509"
-    "log"
-
-    "github.com/aws/aws-sdk-go/service/acm"
-    "github.com/aws/aws-sdk-go/aws"
-    "github.com/aws/aws-sdk-go/aws/session"
+	"crypto/tls"
 )
 
 func getTlsConfig() *tls.Config {
-	sess := session.Must(session.NewSessionWithOptions(session.Options{
-		Config: aws.Config{
-			Region: aws.String("us-east-2"),
-		},
-		Profile: "default",
-	}))
-	svc := acm.New(sess)
-	gci := &acm.GetCertificateInput{}
-	gci.SetCertificateArn("arn:aws:acm:us-east-2:824263434500:certificate/aa0ae6e7-075a-466c-bcb5-8d7874447bcb")
-	ca, err := svc.GetCertificate(gci)
-	if err != nil {
-		log.Fatal(err)
-	}
-    	caCertPool := x509.NewCertPool()
-    	caCertPool.AppendCertsFromPEM([]byte(*ca.CertificateChain))
-
-    	tlsConfig := &tls.Config{
-		MinVersion: tls.VersionTLS12,
-		CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
+	tlsConfig := &tls.Config{
+		MinVersion:               tls.VersionTLS12,
+		CurvePreferences:         []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
 		PreferServerCipherSuites: true,
 		CipherSuites: []uint16{
 			tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
-            		tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
-            		tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
-            		tls.TLS_RSA_WITH_AES_256_CBC_SHA,
+			tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
+			tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
+			tls.TLS_RSA_WITH_AES_256_CBC_SHA,
 		},
-        	RootCAs:      caCertPool,
-    	}
-    	tlsConfig.BuildNameToCertificate()
+	}
+	tlsConfig.BuildNameToCertificate()
 	return tlsConfig
 }
--- a/router/pages.go
+++ b/router/pages.go
@@ -6,6 +6,7 @@
 	"errors"
 	"fmt"
 	"html/template"
+	"os"
 	"path"
 	"strings"
 
@@ -53,13 +54,25 @@
 	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 {
+		errs = append(errs, errors.New("Unable to locate templates/plugins"))
+		return errs
+	}
+	dirs, err := extra.Readdirnames(0)
+	for n, dir := range dirs {
+		dirs[n] = path.Join("templates", "plugins", dir)
+	}
+	// TODO(halfwit) Validate our plugin templates here as well
+	dirs = append(dirs, hd, fd, ed, ld)
 	printer := message.NewPrinter(message.MatchLanguage("en"))
 	for _, item := range pagecache {
 		var err error
 		tp := path.Join("templates", item.Path) + ".tpl"
-
 		t := template.New(path.Base(tp))
-		item.tmpl, err = t.ParseFiles(tp, hd, ed, fd, ld)
+		// TODO(halfwit) Contemplate only adding templates for plugins each page uses
+		item.tmpl, _ = t.ParseFiles(dirs...)
+		item.tmpl, err = t.ParseFiles(tp)
 		if err != nil {
 			errs = append(errs, fmt.Errorf("parsing in %s - %v", path.Dir(item.Path), err))
 			continue
--- a/templates/patient/offer.tpl
+++ b/templates/patient/offer.tpl
@@ -2,12 +2,7 @@
 	<main>
 	 <h2>{{.mainHeader}}</h2>
 	 <form action="findspecialty">
-		<label for="Specialty">{{.specialty}}</label>
-	 	<select name="Specialty">
-		{{range $id, $name := .specialties}}
-			<option value="{{$id}}">{{$name}}</option>
-		{{end}}
-		</select>
+		{{template "specialty" .specialties}}
 		<br/>
 		<label for="Amount">{{.bcu}} <i>({{.rate}})</i></label>
 		<input type="text" name="Amount" size="15" maxlength="10" />
--- /dev/null
+++ b/templates/plugins/specialties.tpl
@@ -1,0 +1,8 @@
+{{define "specialty"}}				
+<label for="Specialty">{{.specialty}}</label>
+	<select name="Specialty">
+        {{range $id, $name := .}}
+		<option value="{{$id}}">{{$name}}</option>
+	    {{end}}		
+    </select>
+{{end}}
\ No newline at end of file