diff --git a/migrations/0_29092022_setup_tables.sql b/migrations/0_29092022_setup_tables.sql index 1e8ace7..ef54ae4 100644 --- a/migrations/0_29092022_setup_tables.sql +++ b/migrations/0_29092022_setup_tables.sql @@ -3,6 +3,7 @@ CREATE TABLE branch ( id INT AUTO_INCREMENT, type ENUM('NMLS', 'FSRA') NOT NULL, + letterhead BLOB(102400) NOT NULL DEFAULT 0, num VARCHAR(40) NOT NULL, PRIMARY KEY (id) ); @@ -15,6 +16,8 @@ CREATE TABLE user ( password CHAR(64) NOT NULL, verified BOOLEAN, branch_id INT NULL, + avatar BLOB(102400) NOT NULL DEFAULT 0, + letterhead BLOB(102400) NOT NULL DEFAULT 0, /* The password should be a SHA256 hash in hex format. It's length doesn't * vary */ country ENUM('Canada', 'USA'), diff --git a/skouter.go b/skouter.go index fb40891..73a9095 100644 --- a/skouter.go +++ b/skouter.go @@ -148,14 +148,16 @@ var ( ) var paths = map[string]string { - "home": "home.tpl", - "terms": "terms.tpl", - "app": "app.tpl", + "home": "views/home.tpl", + "terms": "views/terms.tpl", + "app": "views/app.tpl", + "test": "views/test.tpl", } var pages = map[string]Page { "home": cache("home", "Home"), "terms": cache("terms", "Terms and Conditions"), + "test": cache("test", "PDF test"), "app": cache("app", "App"), } @@ -176,7 +178,7 @@ func (c UserClaims) Valid() error { } func cache(name string, title string) Page { - var p = []string{"master.tpl", paths[name]} + var p = []string{"views/master.tpl", paths[name]} tpl := template.Must(template.ParseFiles(p...)) return Page{tpl: tpl, Title: title, @@ -1512,6 +1514,47 @@ func validateEstimate(w http.ResponseWriter, db *sql.DB, r *http.Request) { if err != nil { http.Error(w, err.Error(), 406); return } } +func showPDF(w http.ResponseWriter, r *http.Request) { + // var args []string + + // p := r.URL.Path + db, err := sql.Open("mysql", + fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/skouter", + config["DBUser"], + config["DBPass"])) + + // w.Header().Set("Content-Type", "application/json; charset=UTF-8") + err = db.Ping() + if err != nil { + fmt.Println("Bad database configuration: %v\n", err) + panic(err) + // maybe os.Exit(1) instead + } + + var pa = template.Must(template.ParseFiles("views/master.tpl", + "views/test.tpl")) + + // claims, err := getClaims(r) + if err != nil { w.WriteHeader(500); return } + users, err := queryUsers(db, 1) + + info := struct { + Title string + Name string + User User + }{ + Title: "test PDF", + Name: "idk-random-name", + User: users[0], + } + + // fmt.Println(info) + + err = pa.Execute(w, info) + if err != nil {fmt.Println(err)} + +} + func api(w http.ResponseWriter, r *http.Request) { var args []string @@ -1595,9 +1638,9 @@ func api(w http.ResponseWriter, r *http.Request) { } func route(w http.ResponseWriter, r *http.Request) { - var page Page + var page Page var args []string - p := r.URL.Path + p := r.URL.Path switch { case r.Method == "GET" && match(p, "/", &args): @@ -1606,6 +1649,9 @@ func route(w http.ResponseWriter, r *http.Request) { page = pages[ "terms" ] case match(p, "/app", &args): page = pages[ "app" ] + case match(p, "/test", &args): + showPDF(w, r) + return default: http.NotFound(w, r) return diff --git a/app.tpl b/views/app.tpl similarity index 100% rename from app.tpl rename to views/app.tpl diff --git a/home.tpl b/views/home.tpl similarity index 100% rename from home.tpl rename to views/home.tpl diff --git a/master.tpl b/views/master.tpl similarity index 100% rename from master.tpl rename to views/master.tpl diff --git a/terms.tpl b/views/terms.tpl similarity index 100% rename from terms.tpl rename to views/terms.tpl diff --git a/views/test.tpl b/views/test.tpl new file mode 100644 index 0000000..2daecca --- /dev/null +++ b/views/test.tpl @@ -0,0 +1,11 @@ +{{define "header"}} +
+
+{{end}} + +{{define "main"}} +
+
hello world {{.User.Title}}
+
TESTING
+
+{{end}}