diff --git a/cmd/web/handlers_user.go b/cmd/web/handlers_user.go
index 391eb13..a530641 100644
--- a/cmd/web/handlers_user.go
+++ b/cmd/web/handlers_user.go
@@ -251,6 +251,7 @@ func (app *application) putUserSettings(w http.ResponseWriter, r *http.Request)
if !form.Valid() {
// TODO: rerender template with errors
app.clientError(w, http.StatusUnprocessableEntity)
+ return
}
user.Settings.LocalTimezone, err = time.LoadLocation(form.LocalTimezone)
if err != nil {
diff --git a/cmd/web/main.go b/cmd/web/main.go
index b9dba2f..8faa38d 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
+ "path/filepath"
"strconv"
"strings"
"time"
@@ -57,14 +58,16 @@ type application struct {
}
type appInstaller struct {
- app *application
- srv *http.Server
- installModel models.InstallModelInterface
+ app *application
+ srv *http.Server
+ installModel models.InstallModelInterface
+ migrationsPath string
}
func main() {
addr := flag.String("addr", ":3000", "HTTP network address")
dsn := flag.String("dsn", "guestbook.db", "data source name")
+ migrations := flag.String("migrations", "migrations", "folder containing sql migrations")
debug := flag.Bool("debug", false, "enable debug mode")
env := flag.String("env", ".env", ".env file path")
flag.Parse()
@@ -113,8 +116,9 @@ func main() {
}
installer := &appInstaller{
- app: app,
- installModel: &models.InstallModel{DB: db},
+ app: app,
+ installModel: &models.InstallModel{DB: db},
+ migrationsPath: filepath.Clean(*migrations),
}
installer.srv = &http.Server{
Addr: *addr,
@@ -301,7 +305,7 @@ func walkTzDir(path string, zones []string) []string {
func runInstaller(i *appInstaller) error {
i.app.logger.Info("Performing migrations")
- err := i.installModel.SetupDatabase()
+ err := i.installModel.SetupDatabase(i.migrationsPath)
if err != nil {
return err
}
@@ -309,6 +313,10 @@ func runInstaller(i *appInstaller) error {
if installed {
return nil
}
+ err = i.app.users.InitializeSettingsMap()
+ if err != nil {
+ return err
+ }
i.app.logger.Info("App not installed, running installer...")
i.app.logger.Info("Starting installation server", slog.Any("addr", i.srv.Addr))
if i.app.debug {
diff --git a/cmd/web/routes.go b/cmd/web/routes.go
index 932e778..31b8d0f 100644
--- a/cmd/web/routes.go
+++ b/cmd/web/routes.go
@@ -43,7 +43,6 @@ func (app *application) routes() http.Handler {
mux.Handle("POST /users/logout", protected.ThenFunc(app.postUserLogout))
mux.Handle("GET /users/settings", protected.ThenFunc(app.getUserSettings))
mux.Handle("PUT /users/settings", protected.ThenFunc(app.putUserSettings))
- mux.Handle("GET /guestbooks", protected.ThenFunc(app.getAllGuestbooks))
mux.Handle("GET /websites", protected.ThenFunc(app.getWebsiteList))
mux.Handle("GET /websites/create", protected.ThenFunc(app.getWebsiteCreate))
mux.Handle("POST /websites/create", protected.ThenFunc(app.postWebsiteCreate))
@@ -59,6 +58,7 @@ func (app *application) routes() http.Handler {
mux.Handle("GET /websites/{id}/dashboard/guestbook/customize", protected.ThenFunc(app.getComingSoon))
adminOnly := protected.Append(app.requireAdmin)
+ mux.Handle("GET /guestbooks", adminOnly.ThenFunc(app.getAllGuestbooks))
mux.Handle("GET /admin", adminOnly.ThenFunc(app.getAdminPanelLanding))
mux.Handle("GET /admin/users", adminOnly.ThenFunc(app.getAdminPanelAllUsers))
mux.Handle("GET /admin/users/{id}", adminOnly.ThenFunc(app.getAdminPanelUser))
diff --git a/internal/models/install.go b/internal/models/install.go
index 872d75d..61595b0 100644
--- a/internal/models/install.go
+++ b/internal/models/install.go
@@ -3,6 +3,8 @@ package models
import (
"database/sql"
"errors"
+ "fmt"
+ "path/filepath"
"time"
"github.com/golang-migrate/migrate/v4"
@@ -16,17 +18,19 @@ type InstallModel struct {
}
type InstallModelInterface interface {
- SetupDatabase() error
+ SetupDatabase(migrations string) error
SetInstalledFlag() error
GetInstalledFlag() (bool, error)
}
-func (m *InstallModel) SetupDatabase() error {
+func (m *InstallModel) SetupDatabase(migrations string) error {
driver, err := sqlite3.WithInstance(m.DB, &sqlite3.Config{})
if err != nil {
return err
}
- mi, err := migrate.NewWithDatabaseInstance("file://migrations", "sqlite", driver)
+ mFolder := fmt.Sprintf("file://%s", filepath.Clean(migrations))
+ fmt.Printf("migrations %s\n", mFolder)
+ mi, err := migrate.NewWithDatabaseInstance(mFolder, "sqlite", driver)
if err != nil {
return err
}
diff --git a/ui/views/common.templ b/ui/views/common.templ
index c0463fb..7482489 100644
--- a/ui/views/common.templ
+++ b/ui/views/common.templ
@@ -65,7 +65,6 @@ templ topNav(data CommonData) {
if data.IsAuthenticated {
- - All Guestbooks
- My Websites
- Settings
if slices.Contains(data.CurrentUser.Groups, models.AdminGroup) {
@@ -109,6 +108,10 @@ templ base(title string, data CommonData) {
@commonHeader()
@topNav(data)
+
if data.Flash != "" {
{ data.Flash }
}
diff --git a/ui/views/common_templ.go b/ui/views/common_templ.go
index 82a92c6..495f90f 100644
--- a/ui/views/common_templ.go
+++ b/ui/views/common_templ.go
@@ -130,7 +130,7 @@ func topNav(data CommonData) templ.Component {
return templ_7745c5c3_Err
}
if data.IsAuthenticated {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "- All Guestbooks
- My Websites
- Settings
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "- My Websites
- Settings
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -147,7 +147,7 @@ func topNav(data CommonData) templ.Component {
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(hxHeaders)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 74, Col: 66}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 73, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
@@ -234,7 +234,7 @@ func base(title string, data CommonData) templ.Component {
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(title)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 99, Col: 17}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 98, Col: 17}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
@@ -247,7 +247,7 @@ func base(title string, data CommonData) templ.Component {
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(`{"includeIndicatorStyles":false}`)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 102, Col: 72}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 101, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
@@ -265,7 +265,7 @@ func base(title string, data CommonData) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -277,7 +277,7 @@ func base(title string, data CommonData) templ.Component {
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(data.Flash)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 113, Col: 43}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 116, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@@ -369,7 +369,7 @@ func pagination(baseUrl string, currentPage int64, recordsAmount int64, recordsP
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", i+1))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 137, Col: 28}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 140, Col: 28}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
@@ -392,7 +392,7 @@ func pagination(baseUrl string, currentPage int64, recordsAmount int64, recordsP
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", i+1))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 139, Col: 55}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/views/common.templ`, Line: 142, Col: 55}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
diff --git a/ui/views/home.templ b/ui/views/home.templ
index b3693e0..9b62159 100644
--- a/ui/views/home.templ
+++ b/ui/views/home.templ
@@ -5,10 +5,6 @@ templ Home(title string, data CommonData) {
Welcome
Welcome to webweav.ing, a collection of webmastery tools created by the 32-Bit Cafe.
-
}
}
diff --git a/ui/views/home_templ.go b/ui/views/home_templ.go
index 03173a0..d70dd67 100644
--- a/ui/views/home_templ.go
+++ b/ui/views/home_templ.go
@@ -41,7 +41,7 @@ func Home(title string, data CommonData) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Welcome
Welcome to webweav.ing, a collection of webmastery tools created by the 32-Bit Cafe.
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Welcome
Welcome to webweav.ing, a collection of webmastery tools created by the 32-Bit Cafe.
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}