diff --git a/config/config.go b/config/config.go index 7fadcc8..d829f46 100644 --- a/config/config.go +++ b/config/config.go @@ -9,10 +9,11 @@ import ( ) type Config struct { - Port string `yaml:"port"` - DatabasePath string `yaml:"database_path"` - CertificatePath string `yaml:"certificate_path"` - PrivateKeyPath string `yaml:"private_key_path"` + Port string `yaml:"port"` + DatabasePath string `yaml:"database_path"` + CertificatePath string `yaml:"certificate_path"` + PrivateKeyPath string `yaml:"private_key_path"` + AllowRegistration bool `yaml:"allow_registration"` } const configPath = "./appdata/config.yaml" @@ -34,10 +35,11 @@ func CheckIfExists() error { } defaultConfig := Config{ - Port: "8080", - DatabasePath: "./appdata/database.db", - CertificatePath: "./appdata/cert.pem", - PrivateKeyPath: "./appdata/key.pem", + Port: "8080", + DatabasePath: "./appdata/database.db", + CertificatePath: "./appdata/cert.pem", + PrivateKeyPath: "./appdata/key.pem", + AllowRegistration: true, } data, err := yaml.Marshal(defaultConfig) diff --git a/frontend/handler.go b/frontend/handler.go index 249d0b0..cbb2c05 100644 --- a/frontend/handler.go +++ b/frontend/handler.go @@ -39,7 +39,7 @@ func Home(w http.ResponseWriter, r *http.Request) { err := home.Execute(w, struct { Name string }{ - Name: "Miau", + Name: "Home", }) if err != nil { return @@ -51,7 +51,7 @@ func Dashboard(w http.ResponseWriter, r *http.Request) { err := dashboard.ExecuteTemplate(w, "base.html", struct { Title string }{ - Title: "Miau", + Title: "Dashboard", }) if err != nil { return @@ -62,7 +62,7 @@ func Inventory(w http.ResponseWriter, r *http.Request) { err := inventory.ExecuteTemplate(w, "base.html", struct { Title string }{ - Title: "Miau", + Title: "Inventory", }) if err != nil { return @@ -73,7 +73,7 @@ func Items(w http.ResponseWriter, r *http.Request) { err := item.ExecuteTemplate(w, "base.html", struct { Title string }{ - Title: "Miau", + Title: "Items", }) if err != nil { return @@ -84,7 +84,7 @@ func Locations(w http.ResponseWriter, r *http.Request) { err := locations.ExecuteTemplate(w, "base.html", struct { Title string }{ - Title: "Miau", + Title: "Locations", }) if err != nil { return @@ -95,7 +95,7 @@ func Projects(w http.ResponseWriter, r *http.Request) { err := projects.ExecuteTemplate(w, "base.html", struct { Title string }{ - Title: "Miau", + Title: "Projects", }) if err != nil { return diff --git a/frontend/htmx/register_blocked.html b/frontend/htmx/register_blocked.html new file mode 100644 index 0000000..360f9f1 --- /dev/null +++ b/frontend/htmx/register_blocked.html @@ -0,0 +1,134 @@ + + + + + + Registration Disabled - MiauInv + + + + +
+

Registration

+
Create a new account
+ +
+ Access Denied: Public registration is currently disabled for this system. Please contact your system administrator to request an account. +
+ + +
+ + + \ No newline at end of file diff --git a/server/server.go b/server/server.go index 2929969..81d37bc 100644 --- a/server/server.go +++ b/server/server.go @@ -12,11 +12,12 @@ import ( ) type Server struct { - Port string - JWTSecret []byte - DatabasePath string - CertificatePath string - PrivateKeyPath string + Port string + JWTSecret []byte + DatabasePath string + CertificatePath string + PrivateKeyPath string + AllowRegistration bool } func InitServer() *Server { @@ -44,11 +45,12 @@ func InitServer() *Server { } return &Server{ - Port: cfg.Port, - JWTSecret: []byte(jwtSecret), - DatabasePath: cfg.DatabasePath, - CertificatePath: cfg.CertificatePath, - PrivateKeyPath: cfg.PrivateKeyPath, + Port: cfg.Port, + JWTSecret: []byte(jwtSecret), + DatabasePath: cfg.DatabasePath, + CertificatePath: cfg.CertificatePath, + PrivateKeyPath: cfg.PrivateKeyPath, + AllowRegistration: cfg.AllowRegistration, } } @@ -61,21 +63,26 @@ func (this *Server) Run() { // mux.HandleFunc("/", frontend.Home) 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))) + if this.AllowRegistration { + mux.HandleFunc("/register", utils.RenderFile("frontend/htmx/register.html")) + } else { + mux.HandleFunc("/register", utils.RenderFile("frontend/htmx/register_blocked.html")) + } // // API // mux.HandleFunc("/api/login", handlers.APILogin) - mux.HandleFunc("/api/register", handlers.APIRegister) mux.HandleFunc("/api/refresh", handlers.RefreshToken) mux.Handle("/api/logout", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(handlers.Logout))) + if this.AllowRegistration { + mux.HandleFunc("/api/register", handlers.APIRegister) + } mux.Handle("/api/item", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(handlers.Item))) mux.Handle("/api/location", auth.AuthMiddleware(this.JWTSecret)(http.HandlerFunc(handlers.Location)))