Added more frontend and some more login logic

This commit is contained in:
2026-06-05 21:58:10 +02:00
parent 6543149dab
commit 52d551ab39
22 changed files with 1043 additions and 173 deletions

View File

@@ -1,9 +1,11 @@
package server
import (
"MiauInv/auth"
"MiauInv/config"
"MiauInv/frontend"
"MiauInv/handlers"
utils "MiauInv/util"
"log"
"net/http"
"os"
@@ -58,32 +60,32 @@ func (this *Server) Run() {
// FRONTEND
//
mux.HandleFunc("/", frontend.Home)
mux.HandleFunc("/dashboard", frontend.Dashboard)
mux.HandleFunc("/login", utils.RenderFile("frontend/htmx/login.html"))
mux.HandleFunc("/register", utils.RenderFile("frontend/htmx/register.html"))
mux.Handle("/dashboard", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(frontend.Dashboard)))
mux.Handle("/inventory", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(frontend.Inventory)))
mux.Handle("/items", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(frontend.Items)))
mux.Handle("/locations", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(frontend.Locations)))
mux.Handle("/projects", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(frontend.Projects)))
//
// API
//
// Public
mux.HandleFunc("/api/login", handlers.Login)
mux.HandleFunc("/api/register", handlers.Register)
mux.HandleFunc("/api/login", handlers.APILogin)
mux.HandleFunc("/api/register", handlers.APIRegister)
mux.HandleFunc("/api/refresh", handlers.RefreshToken)
mux.HandleFunc("/api/logout", handlers.Logout)
mux.Handle("/api/logout", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(handlers.Logout)))
mux.HandleFunc("/api/items", handlers.GetItems)
mux.HandleFunc("/api/items/create", handlers.CreateItem)
mux.HandleFunc("/api/locations/create", handlers.CreateLocation)
mux.HandleFunc("/api/projects/create", handlers.CreateProject)
mux.HandleFunc("/api/item", handlers.GetItems)
mux.HandleFunc("/api/locations", handlers.CreateLocation)
mux.HandleFunc("/api/project", handlers.CreateProject)
mux.HandleFunc("/api/stock/add", handlers.AddStock)
mux.HandleFunc("/api/project-items/add", handlers.AllocateToProject)
// Assets
mux.HandleFunc("/assets/", frontend.Assets)
// Login required
// Admin-only
log.Printf("Listening on port %s", this.Port)
log.Fatal(http.ListenAndServeTLS(":"+this.Port, this.CertificatePath, this.PrivateKeyPath, mux))
}