all repos — nirvash @ b9d971140a92f8738c6ba1fa59577843e4a120b0

modular CMS using the quartzgun library

nirvash.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

import (
	"net/http"
	core "nilfm.cc/git/nirvash/archetype"
	shell "nilfm.cc/git/nirvash/lfo"
	"nilfm.cc/git/quartzgun/indentalUserDB"
	"nilfm.cc/git/quartzgun/middleware"
	"nilfm.cc/git/quartzgun/renderer"
	"nilfm.cc/git/quartzgun/router"
	"os"
	"path/filepath"
)

func main() {
	cfg := core.ReadConfig()
	udb := indentalUserDB.CreateIndentalUserDB(
		filepath.Join(
			core.GetConfigLocation(),
			"user.db"))
	if core.ProcessCmd(os.Args, udb, cfg) {
		os.Exit(0)
	}
	if cfg.IsNull() {
		cfg.RunWizard()
	}

	cfg.Adapter.Init(cfg)

	rtr := &router.Router{
		StaticPaths: map[string]string{
			"/static": cfg.AssetRoot,
		},
	}

	rtr.Get("/login", renderer.Template(
		"templates/login.html"))

	rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1"))

	rtr.Get("/", middleware.Protected(
		shell.WithAdapter(
			renderer.Template(
				"templates/cms_list.html",
				"templates/header.html",
				"templates/footer.html"), cfg.Adapter), http.MethodGet, udb, "/login"))

	rtr.Get(`/edit/(?P<Slug>\S+)`, middleware.Fortify(middleware.Protected(
		shell.WithAdapter(
			renderer.Template(
				"templates/cms_edit.html",
				"templates/header.html",
				"templates/footer.html"), cfg.Adapter), http.MethodGet, udb, "/login")))

	rtr.Post(`/save/(?P<Slug>\S+)`, middleware.Defend(middleware.Protected(
		shell.WithAdapter(
			shell.EnsurePageData(
				renderer.Template(
					"templates/cms_save.html",
					"templates/header.html",
					"templates/footer.html")), cfg.Adapter), http.MethodGet, udb, "/login"), udb, "/"))

	http.ListenAndServe(":8080", rtr)
}