Refactor server and templates package

This commit is contained in:
Tom Wiesing 2023-01-19 13:22:48 +01:00
parent b6bf0a8900
commit 6ede99d7c6
No known key found for this signature in database
105 changed files with 341 additions and 339 deletions

View file

@ -0,0 +1,67 @@
package legal
import (
"context"
"net/http"
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templates"
_ "embed"
)
type Legal struct {
component.Base
Dependencies struct {
Static *assets.Static
Templating *templates.Templating
}
}
var (
_ component.Routeable = (*Legal)(nil)
)
//go:embed "legal.html"
var legalHTML []byte
var legalTemplate = templates.Parse[legalContext]("legal.html", legalHTML, assets.AssetsDefault)
type legalContext struct {
templates.BaseContext
LegalNotices string
CSRFCookie string
SessionCookie string
AssetsDisclaimer string
}
func (legal *Legal) Routes() component.Routes {
return component.Routes{
Prefix: "/legal/",
Exact: true,
CSRF: false,
}
}
func (legal *Legal) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
tpl := legalTemplate.Prepare(legal.Dependencies.Templating, templates.BaseContextGaps{
Crumbs: []component.MenuItem{
{Title: "Legal", Path: "/legal/"},
},
})
return tpl.HTMLHandler(func(r *http.Request) (lc legalContext, err error) {
lc.LegalNotices = cli.LegalNotices
lc.CSRFCookie = server.CSRFCookie
lc.SessionCookie = server.SessionCookie
lc.AssetsDisclaimer = assets.Disclaimer
return
}), nil
}

View file

@ -0,0 +1,72 @@
{{ template "_base.html" . }}
{{ define "title" }}Legal{{ end }}
{{ define "content" }}
<div class="pure-u-1">
<h2 id="cookies">Cookie Usage</h2>
<p>
Parts of this site use cookies for essential purposes.
<a href="https://en.wikipedia.org/wiki/HTTP_cookie">Wikipedia</a> says that
</p>
<blockquote>
<p>A […] cookie (also called web cookie, Internet cookie, browser cookie, or simply cookie) is a small piece of data sent from a website and stored on the users computer by the users web browser while the user is browsing.</p>
</blockquote>
<p>
This site only uses cookies where necessary; in particular they are only used on access protected sites.
Public sites are cookie-free.
For signed in users only two cookies are used.
<ol>
<li>
The cookie named <code>{{ .CSRFCookie }}</code> is used to prevent <a href="https://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-site request forgery</a>.
</li>
<li>
The cookie named <code>{{ .SessionCookie }}</code> is used to track a distillery user session, so that a user does not constantly have to login again.
It is automatically deleted once a user signs out.
</li>
</ol>
Neither cookie is used beyond the purposes they are required for.
In particular, they are not used for analytics or any other kind of tracking.
</p>
</div>
<div class="pure-u-1">
<h2 id="notices">Legal Notices</h2>
<ul>
<li><a href="#license.backend">Backend</a></li>
<li><a href="#license.frontend">Frontend</a></li>
</ul>
<p>
This site is powered by the <a href="https://github.com/FAU-CDI/wisski-distillery" target="_blank" rel="noopener noreferer">WissKI Distillery</a>.
The project is licensed under the terms of the AGPL Version 3.0 License.
</p>
</div>
<div class="pure-u-1">
<h3 id="license.backend">Backend</h2>
<p>
<small><a href="#notices">Back to Notices</a></small>
</p>
<p>
The backend may contain code from the following projects:
</p>
<pre>{{ .LegalNotices }}</pre>
</div>
<div class="pure-u-1">
<h3 id="license.frontend">Frontend</h2>
<p>
<small><a href="#notices">Back to Notices</a></small>
</p>
<pre>{{ .AssetsDisclaimer }}</pre>
</div>
{{ end }}