Why was this not deleted I do not know

This commit is contained in:
2024-05-26 21:42:39 +01:00
parent cb40df5da7
commit 368b4444a7
8 changed files with 0 additions and 173 deletions
-9
View File
@@ -1,9 +0,0 @@
build: clean
mkdir build
go build -o build/frontend
cp -r ./assets build
touch build/data.db
sqlite3 build/data.db < ./usefulQueries.sql
clean:
rm -r build
-9
View File
@@ -1,9 +0,0 @@
module thermalFax
go 1.22.2
require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/mattn/go-sqlite3 v1.14.22
golang.org/x/crypto v0.22.0
)
-6
View File
@@ -1,6 +0,0 @@
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
-49
View File
@@ -1,49 +0,0 @@
package main
import (
"fmt"
"log"
"net/http"
"thermalFax/controllers"
)
func checkMethod(method string, r *http.Request) bool {
return r.Method == method
}
func main() {
// GET calls
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if !checkMethod(http.MethodGet, r) {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
controllers.EditorPage(w, r)
})
// POST calls
http.HandleFunc("/send-fax", func(w http.ResponseWriter, r *http.Request) {
if !checkMethod(http.MethodPost, r) {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
controllers.SendFax(w, r)
})
http.HandleFunc("/send-login", func(w http.ResponseWriter, r *http.Request) {
if !checkMethod(http.MethodPost, r) {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
controllers.Authenticate(w, r)
})
// Serve the CSS and JS files, we might have to change this
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))
fmt.Println("Starting server on port 8083")
log.Fatal(http.ListenAndServe(":8083", nil))
}
-22
View File
@@ -1,22 +0,0 @@
-- Generate a password
-- htpasswd -bnBC 10 "" kika | tr -d ':\n'
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS sessions(
id INTEGER PRIMARY KEY AUTOINCREMENT,
user TEXT NOT NULL,
token TEXT NOT NULL,
expires INTEGER
);
INSERT INTO
users(name, password)
values(
'user',
'$2y$10$E9TqLeXWU85ZVTz7TCyTbu1S.ZaNV6v6DOmrbxqfMm/ADMkBKLP.O'
);
-19
View File
@@ -1,19 +0,0 @@
package views
import "net/http"
func EditorPage(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
mainPage := HtmlTemplate("./assets/htmx/terminal.tmpl", map[string]interface{}{
"content": HtmlTemplate("./assets/htmx/editor.html", nil),
"renderNavBar": true,
"page": "fax",
})
_, err := w.Write([]byte(mainPage))
if err != nil {
http.Error(w, "Internal error", http.StatusInternalServerError)
return
}
}
-23
View File
@@ -1,23 +0,0 @@
package views
import "net/http"
func LoginPage(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
loginTemplate := HtmlTemplate("./assets/htmx/login.html", map[string]interface{}{
"script": true,
})
loginPage := HtmlTemplate("./assets/htmx/terminal.tmpl", map[string]interface{}{
"content": loginTemplate,
"renderNavBar": true,
"page": "fax",
})
_, err := w.Write([]byte(loginPage))
if err != nil {
http.Error(w, "Internal error", http.StatusInternalServerError)
return
}
}
-36
View File
@@ -1,36 +0,0 @@
package views
import (
"bytes"
"html/template"
"log"
"path"
)
// func loadFile(path string) []byte {
// file, err := os.ReadFile(path)
// if err != nil {
// log.Printf("Unable to open file: %s\n", path)
// }
// return file
// }
func HtmlTemplate(file string, data map[string]interface{}) template.HTML {
templateName := path.Base(file)
tmpl, err := template.New(templateName).ParseFiles(file)
if err != nil {
panic(err)
}
// Use a bytes.Buffer to store the rendered output
var renderedOutput bytes.Buffer
// Render the template
err = tmpl.ExecuteTemplate(&renderedOutput, templateName, data)
if err != nil {
log.Fatalf("Template execution: %v", err)
}
// Now, renderedOutput holds the rendered template
return template.HTML(renderedOutput.String())
}