parent
5693a59784
commit
82696dbc6f
@ -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}}'
|
||||
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
node_modules/
|
||||
tijl.dev
|
||||
tijldev
|
||||
web/static/js/interactive.js
|
||||
web/static/css/styles.css
|
||||
config.yaml
|
||||
|
@ -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 {
|
||||
|
@ -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"`
|
||||
|
@ -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")
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -78,5 +78,5 @@ func HandleCallback(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Redirect("/")
|
||||
return c.Redirect("/loggedin")
|
||||
}
|
||||
|
@ -36,5 +36,5 @@ func Load(ctx context.Context) {
|
||||
|
||||
Verifier = Provider.Verifier(oidcConfig)
|
||||
|
||||
log.Debug().Msg("loaded oidc")
|
||||
log.Info().Msg("loaded oidc")
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
<h2>Welcome to My Go App</h2>
|
||||
<p>This is the homepage.</p>
|
||||
<div>index</div>
|
||||
<div>Signed In: {{.SignedIn}}</div>
|
||||
|
1
web/views/loggedin.html
Normal file
1
web/views/loggedin.html
Normal file
@ -0,0 +1 @@
|
||||
<div>you are now logged in</div>
|
@ -1 +1 @@
|
||||
<a class="btn" href="/auth">Login with TT Authentication Services</a>
|
||||
<a hx-boost="false" class="btn btn-primary" href="/auth">Login with TT Authentication Services</a>
|
||||
|
@ -92,7 +92,7 @@
|
||||
<span class="text-base">{{.T.account}}</span>
|
||||
</a>
|
||||
{{else}}
|
||||
<a class="active flex gap-4" hx-boost="false" href="/login">
|
||||
<a class="active flex gap-4" href="/login">
|
||||
<span class="w-5 text-center">
|
||||
{{icon "login"}}
|
||||
</span>
|
||||
|
Loading…
Reference in New Issue
Block a user