From 1e45ae2ea3497958b2ea6a20137955cfc3bbc964 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Wed, 11 Dec 2024 17:05:12 +0100 Subject: feat: Add UI/Handler login process It adds the whole workflow to store and handle login on both UI and handler level. With that the login information should be available at any point given the context. --- templates/base.qtpl.go | 143 ++++++++++++++++++++++++++----------------------- 1 file changed, 76 insertions(+), 67 deletions(-) (limited to 'templates/base.qtpl.go') diff --git a/templates/base.qtpl.go b/templates/base.qtpl.go index f8ff91f..5bb4532 100644 --- a/templates/base.qtpl.go +++ b/templates/base.qtpl.go @@ -8,57 +8,60 @@ package templates //line templates/base.qtpl:3 -import "strconv" +import "context" //line templates/base.qtpl:4 +import "strconv" + +//line templates/base.qtpl:5 import "time" -//line templates/base.qtpl:6 +//line templates/base.qtpl:7 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line templates/base.qtpl:6 +//line templates/base.qtpl:7 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line templates/base.qtpl:7 +//line templates/base.qtpl:8 var Slug = "" -//line templates/base.qtpl:11 +//line templates/base.qtpl:12 type Page interface { -//line templates/base.qtpl:11 - Title() string -//line templates/base.qtpl:11 - StreamTitle(qw422016 *qt422016.Writer) -//line templates/base.qtpl:11 - WriteTitle(qq422016 qtio422016.Writer) -//line templates/base.qtpl:11 - Content() string -//line templates/base.qtpl:11 - StreamContent(qw422016 *qt422016.Writer) -//line templates/base.qtpl:11 - WriteContent(qq422016 qtio422016.Writer) -//line templates/base.qtpl:11 - Script() string -//line templates/base.qtpl:11 - StreamScript(qw422016 *qt422016.Writer) -//line templates/base.qtpl:11 - WriteScript(qq422016 qtio422016.Writer) -//line templates/base.qtpl:11 - Navbar() string -//line templates/base.qtpl:11 - StreamNavbar(qw422016 *qt422016.Writer) -//line templates/base.qtpl:11 - WriteNavbar(qq422016 qtio422016.Writer) -//line templates/base.qtpl:11 +//line templates/base.qtpl:12 + Title(ctx context.Context) string +//line templates/base.qtpl:12 + StreamTitle(qw422016 *qt422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + WriteTitle(qq422016 qtio422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + Content(ctx context.Context) string +//line templates/base.qtpl:12 + StreamContent(qw422016 *qt422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + WriteContent(qq422016 qtio422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + Script(ctx context.Context) string +//line templates/base.qtpl:12 + StreamScript(qw422016 *qt422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + WriteScript(qq422016 qtio422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + Navbar(ctx context.Context) string +//line templates/base.qtpl:12 + StreamNavbar(qw422016 *qt422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 + WriteNavbar(qq422016 qtio422016.Writer, ctx context.Context) +//line templates/base.qtpl:12 } -//line templates/base.qtpl:20 +//line templates/base.qtpl:21 func FromUInttoString(u *uint) string { if u != nil { return strconv.FormatUint(uint64(*u), 10) @@ -66,21 +69,27 @@ func FromUInttoString(u *uint) string { return "" } -//line templates/base.qtpl:28 +//line templates/base.qtpl:31 func TimeFormat(t time.Time) string { return t.Format("02.01.2006") } -//line templates/base.qtpl:33 +//line templates/base.qtpl:36 func Ignore[T any](v T, _ error) T { return v } +//line templates/base.qtpl:41 +func IsLoggedIn(ctx context.Context) bool { + t, ok := ctx.Value("logged").(bool) + return ok && t +} + // Page prints a page implementing Page interface. -//line templates/base.qtpl:39 -func StreamPageTemplate(qw422016 *qt422016.Writer, p Page) { -//line templates/base.qtpl:39 +//line templates/base.qtpl:48 +func StreamPageTemplate(qw422016 *qt422016.Writer, p Page, ctx context.Context) { +//line templates/base.qtpl:48 qw422016.N().S(` @@ -88,64 +97,64 @@ func StreamPageTemplate(qw422016 *qt422016.Writer, p Page) { `) -//line templates/base.qtpl:45 - p.StreamTitle(qw422016) -//line templates/base.qtpl:45 +//line templates/base.qtpl:54 + p.StreamTitle(qw422016, ctx) +//line templates/base.qtpl:54 qw422016.N().S(` `) -//line templates/base.qtpl:51 - p.StreamNavbar(qw422016) -//line templates/base.qtpl:51 +//line templates/base.qtpl:60 + p.StreamNavbar(qw422016, ctx) +//line templates/base.qtpl:60 qw422016.N().S(`
`) -//line templates/base.qtpl:53 - p.StreamContent(qw422016) -//line templates/base.qtpl:53 +//line templates/base.qtpl:62 + p.StreamContent(qw422016, ctx) +//line templates/base.qtpl:62 qw422016.N().S(`
`) -//line templates/base.qtpl:56 - p.StreamScript(qw422016) -//line templates/base.qtpl:56 +//line templates/base.qtpl:65 + p.StreamScript(qw422016, ctx) +//line templates/base.qtpl:65 qw422016.N().S(` `) -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 } -//line templates/base.qtpl:58 -func WritePageTemplate(qq422016 qtio422016.Writer, p Page) { -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 +func WritePageTemplate(qq422016 qtio422016.Writer, p Page, ctx context.Context) { +//line templates/base.qtpl:67 qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/base.qtpl:58 - StreamPageTemplate(qw422016, p) -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 + StreamPageTemplate(qw422016, p, ctx) +//line templates/base.qtpl:67 qt422016.ReleaseWriter(qw422016) -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 } -//line templates/base.qtpl:58 -func PageTemplate(p Page) string { -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 +func PageTemplate(p Page, ctx context.Context) string { +//line templates/base.qtpl:67 qb422016 := qt422016.AcquireByteBuffer() -//line templates/base.qtpl:58 - WritePageTemplate(qb422016, p) -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 + WritePageTemplate(qb422016, p, ctx) +//line templates/base.qtpl:67 qs422016 := string(qb422016.B) -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 qt422016.ReleaseByteBuffer(qb422016) -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 return qs422016 -//line templates/base.qtpl:58 +//line templates/base.qtpl:67 } -- cgit v1.2.3