From 82696dbc6f95c6e4e78888057a8c31baf5ee08d8 Mon Sep 17 00:00:00 2001 From: tijl Date: Thu, 22 Aug 2024 13:47:16 +0200 Subject: [PATCH] updates --- .gitea/workflows/build.yaml | 9 ++++++++- .gitignore | 1 + internal/assets/svg.go | 2 +- internal/config/config.go | 4 +++- internal/db/db.go | 4 ++-- internal/handlers/auth.go | 11 +++++++++++ internal/handlers/routes.go | 1 + internal/i18n/i18n.go | 4 ++-- internal/oidc/handler.go | 2 +- internal/oidc/oidc.go | 2 +- internal/service/main.go | 4 +++- modules/web/app.go | 6 +++++- modules/web/common.go | 2 ++ web/views/index.html | 3 +-- web/views/loggedin.html | 1 + web/views/login.html | 2 +- web/views/partials/menu.html | 2 +- 17 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 web/views/loggedin.html diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index d4aaa6a..0443ab6 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -40,6 +40,13 @@ jobs: go-version: "1.22" - name: Build - run: go build -v ./... + run: go build -o tijldev cmd/server/main.go + + - name: Release + uses: https://gitea.com/actions/release-action@main + with: + files: |- + tijldev + api_key: '${{secrets.RELEASE_TOKEN}}' diff --git a/.gitignore b/.gitignore index 85a2aca..42f6b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ tijl.dev +tijldev web/static/js/interactive.js web/static/css/styles.css config.yaml diff --git a/internal/assets/svg.go b/internal/assets/svg.go index 7d4d939..b0305a3 100644 --- a/internal/assets/svg.go +++ b/internal/assets/svg.go @@ -39,7 +39,7 @@ func loadSVGs() { log.Debug().Str("filename", filename).Msg("assets.loadSVGs: loaded") } - log.Debug().Msg("loaded svg files") + log.Info().Msg("loaded svg files") } func Svg(name string) template.HTML { diff --git a/internal/config/config.go b/internal/config/config.go index 5933926..9624c3d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,10 +25,12 @@ func Load() { log.Fatal().Err(err) } - log.Debug().Msg("loaded config") + log.Info().Msg("loaded config") } type ConfigType struct { + Host string `yaml:"host"` + Port int `yaml:"port"` UrlBase string `yaml:"url_base"` JsonLogging bool `yaml:"log_json"` DB string `yaml:"database"` diff --git a/internal/db/db.go b/internal/db/db.go index 150c6ee..ff002f1 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -25,7 +25,7 @@ func Load() { } //defer DB.Close() Queries = dbmanager.New(DB) - log.Debug().Msg("connected to database") + log.Info().Msg("connected to database") /* Migrate @@ -46,6 +46,6 @@ func Load() { if (migerr != nil) && (!errors.Is(migerr, migrate.ErrNoChange)) { log.Fatal().Err(migerr).Msg("failed to run migrations") } - log.Debug().Msg("migrated database") + log.Info().Msg("migrated database") } diff --git a/internal/handlers/auth.go b/internal/handlers/auth.go index 7b96c12..70263d4 100644 --- a/internal/handlers/auth.go +++ b/internal/handlers/auth.go @@ -19,6 +19,17 @@ func loginHandler(c *fiber.Ctx) error { } } +func loggedinHandler(c *fiber.Ctx) error { + _, err := user.GetSession(c) + if err != nil { + return c.Redirect("/login") + } else { + data := *web.Common(c) + data["Title"] = i18n.Translate(c, "account") + return c.Render("loggedin", data, "layouts/base") + } +} + func authHandler(c *fiber.Ctx) error { _, err := user.GetSession(c) if err == nil { diff --git a/internal/handlers/routes.go b/internal/handlers/routes.go index 781aefd..88b2d58 100644 --- a/internal/handlers/routes.go +++ b/internal/handlers/routes.go @@ -40,6 +40,7 @@ func routes(app *fiber.App) { return c.Render("about", data, "layouts/base") }) app.Get("/login", loginHandler) + app.Get("/loggedin", loggedinHandler) app.Get("/account", accountHandler) app.Get("/logout", logoutHandler) diff --git a/internal/i18n/i18n.go b/internal/i18n/i18n.go index 4bc5a44..416f24c 100644 --- a/internal/i18n/i18n.go +++ b/internal/i18n/i18n.go @@ -45,11 +45,11 @@ func Load() { continue } - log.Debug().Str("lang", lang).Msg("i18n.Load: loaded") + log.Debug().Str("filename", file.Name()).Msg("i18n.Load: loaded") translations[lang] = messages } - log.Debug().Msg("loaded translations") + log.Info().Msg("loaded translations") } func Translate(c *fiber.Ctx, key string) string { diff --git a/internal/oidc/handler.go b/internal/oidc/handler.go index 0bb735e..dcc6de3 100644 --- a/internal/oidc/handler.go +++ b/internal/oidc/handler.go @@ -78,5 +78,5 @@ func HandleCallback(c *fiber.Ctx) error { return err } - return c.Redirect("/") + return c.Redirect("/loggedin") } diff --git a/internal/oidc/oidc.go b/internal/oidc/oidc.go index 5c090c2..4e63667 100644 --- a/internal/oidc/oidc.go +++ b/internal/oidc/oidc.go @@ -36,5 +36,5 @@ func Load(ctx context.Context) { Verifier = Provider.Verifier(oidcConfig) - log.Debug().Msg("loaded oidc") + log.Info().Msg("loaded oidc") } diff --git a/internal/service/main.go b/internal/service/main.go index f632b7a..363c592 100644 --- a/internal/service/main.go +++ b/internal/service/main.go @@ -2,6 +2,7 @@ package service import ( "context" + "fmt" "net/http" "git.tijl.dev/tijl/tijl.dev/internal/assets" @@ -58,7 +59,8 @@ func Listen() { web.Setup(app) // Listen web server - if err := app.Listen(":3000"); err != nil { + log.Info().Int("port", config.Config.Port).Str("host", config.Config.Host).Msg("listening...") + if err := app.Listen(fmt.Sprintf("%v:%v", config.Config.Host, config.Config.Port)); err != nil { log.Fatal().Err(err).Msg("Fiber app error") } diff --git a/modules/web/app.go b/modules/web/app.go index 20fbd91..1a1d469 100644 --- a/modules/web/app.go +++ b/modules/web/app.go @@ -1,6 +1,9 @@ package web -import "github.com/gofiber/fiber/v2" +import ( + log "git.tijl.dev/tijl/tijl.dev/modules/logger" + "github.com/gofiber/fiber/v2" +) /* Basic system for being able to add routes from other packages @@ -9,6 +12,7 @@ Basic system for being able to add routes from other packages var setupFuncs []func(*fiber.App) func RegisterAppSetupFunc(function func(*fiber.App)) { + log.Debug().Msg("web.RegisterAppSetupFunc: registered a function") setupFuncs = append(setupFuncs, function) } diff --git a/modules/web/common.go b/modules/web/common.go index 16b7236..3431a41 100644 --- a/modules/web/common.go +++ b/modules/web/common.go @@ -1,6 +1,7 @@ package web import ( + log "git.tijl.dev/tijl/tijl.dev/modules/logger" "github.com/gofiber/fiber/v2" ) @@ -8,6 +9,7 @@ var commons *fiber.Map = &fiber.Map{} var commonFunctions []func(*fiber.Ctx, *fiber.Map) func RegisterCommon(function func(*fiber.Ctx, *fiber.Map)) { + log.Debug().Msg("web.RegisterCommon: registered a function") commonFunctions = append(commonFunctions, function) } diff --git a/web/views/index.html b/web/views/index.html index 4cec2ea..54609fe 100644 --- a/web/views/index.html +++ b/web/views/index.html @@ -1,3 +1,2 @@ -

Welcome to My Go App

-

This is the homepage.

+
index
Signed In: {{.SignedIn}}
diff --git a/web/views/loggedin.html b/web/views/loggedin.html new file mode 100644 index 0000000..8883ecb --- /dev/null +++ b/web/views/loggedin.html @@ -0,0 +1 @@ +
you are now logged in
diff --git a/web/views/login.html b/web/views/login.html index 7a64efe..2a2464c 100644 --- a/web/views/login.html +++ b/web/views/login.html @@ -1 +1 @@ -Login with TT Authentication Services +Login with TT Authentication Services diff --git a/web/views/partials/menu.html b/web/views/partials/menu.html index 3ea9481..846058a 100644 --- a/web/views/partials/menu.html +++ b/web/views/partials/menu.html @@ -92,7 +92,7 @@ {{.T.account}} {{else}} - + {{icon "login"}}