Bugfixes in preparation for deployment #44
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -65,7 +65,6 @@ templ topNav(data CommonData) {
|
||||
</div>
|
||||
<ul class="nav-links">
|
||||
if data.IsAuthenticated {
|
||||
<li><a href="/guestbooks">All Guestbooks</a></li>
|
||||
<li><a href="/websites">My Websites</a></li>
|
||||
<li><a href="/users/settings">Settings</a></li>
|
||||
if slices.Contains(data.CurrentUser.Groups, models.AdminGroup) {
|
||||
@ -109,6 +108,10 @@ templ base(title string, data CommonData) {
|
||||
@commonHeader()
|
||||
@topNav(data)
|
||||
<main role="main">
|
||||
<aside class="notice" role="alert" aria-labelledby="service-status">
|
||||
<h3 id="service-status" class="sr-only">Service Status Notice</h3>
|
||||
<p><strong>Important:</strong> This service is in a beta state. Please report any bugs or issues to the <a href="https://git.32bit.cafe/32bitcafe/webweav.ing/issues/">git repository</a>.</p>
|
||||
</aside>
|
||||
if data.Flash != "" {
|
||||
<div class="notice flash">{ data.Flash }</div>
|
||||
}
|
||||
|
||||
@ -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, "<li><a href=\"/guestbooks\">All Guestbooks</a></li><li><a href=\"/websites\">My Websites</a></li><li><a href=\"/users/settings\">Settings</a></li>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<li><a href=\"/websites\">My Websites</a></li><li><a href=\"/users/settings\">Settings</a></li>")
|
||||
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, "<main role=\"main\">")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<main role=\"main\"><aside class=\"notice\" role=\"alert\" aria-labelledby=\"service-status\"><h3 id=\"service-status\" class=\"sr-only\">Service Status Notice</h3><p><strong>Important:</strong> This service is in a beta state. Please report any bugs or issues to the <a href=\"https://git.32bit.cafe/32bitcafe/webweav.ing/issues/\">git repository</a>.</p></aside>")
|
||||
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 {
|
||||
|
||||
@ -5,10 +5,6 @@ templ Home(title string, data CommonData) {
|
||||
<section aria-labelledby="welcome-heading">
|
||||
<h2 id="welcome-heading">Welcome</h2>
|
||||
<p>Welcome to webweav.ing, a collection of webmastery tools created by the <a href="https://32bit.cafe" rel="noopener">32-Bit Cafe</a>.</p>
|
||||
<aside class="notice" role="alert" aria-labelledby="service-status">
|
||||
<h3 id="service-status" class="sr-only">Service Status Notice</h3>
|
||||
<p><strong>Important:</strong> This service is in a pre-alpha state. Your account and data can disappear at any time.</p>
|
||||
</aside>
|
||||
</section>
|
||||
}
|
||||
}
|
||||
|
||||
@ -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, "<section aria-labelledby=\"welcome-heading\"><h2 id=\"welcome-heading\">Welcome</h2><p>Welcome to webweav.ing, a collection of webmastery tools created by the <a href=\"https://32bit.cafe\" rel=\"noopener\">32-Bit Cafe</a>.</p><aside class=\"notice\" role=\"alert\" aria-labelledby=\"service-status\"><h3 id=\"service-status\" class=\"sr-only\">Service Status Notice</h3><p><strong>Important:</strong> This service is in a pre-alpha state. Your account and data can disappear at any time.</p></aside></section>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<section aria-labelledby=\"welcome-heading\"><h2 id=\"welcome-heading\">Welcome</h2><p>Welcome to webweav.ing, a collection of webmastery tools created by the <a href=\"https://32bit.cafe\" rel=\"noopener\">32-Bit Cafe</a>.</p></section>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user