mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 07:34:06 +00:00
Load templates with overlapfs to allow custom templates
This commit is contained in:
parent
bf39f4421b
commit
3ef2923e52
3
go.mod
3
go.mod
@ -4,9 +4,11 @@ go 1.21.1
|
||||
|
||||
require (
|
||||
github.com/1f349/cache v0.0.2
|
||||
github.com/1f349/overlapfs v0.0.1
|
||||
github.com/1f349/violet v0.0.10
|
||||
github.com/MrMelon54/exit-reload v0.0.1
|
||||
github.com/MrMelon54/mjwt v0.1.1
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||
github.com/google/subcommands v1.2.0
|
||||
github.com/google/uuid v1.3.1
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
@ -17,7 +19,6 @@ require (
|
||||
require (
|
||||
github.com/MrMelon54/rescheduler v0.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -1,6 +1,8 @@
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/1f349/cache v0.0.2 h1:27QD6zPd9xYyvh9V1qqWq+EAt5+N+qvyGWKfnjMrhP8=
|
||||
github.com/1f349/cache v0.0.2/go.mod h1:LibAMy13dF0KO1fQA9aEjZPBCB6Y4b5kKYEQJUqc2rQ=
|
||||
github.com/1f349/overlapfs v0.0.1 h1:LAxBolrXFAgU0yqZtXg/C/aaPq3eoQSPpBc49BHuTp0=
|
||||
github.com/1f349/overlapfs v0.0.1/go.mod h1:I6aItQycr7nrzplmfNXp/QF9tTmKRSgY3fXmu/7Ky2o=
|
||||
github.com/1f349/violet v0.0.10 h1:2HuQq7SddV60JZ4Xr7DmmhTOPbjiF+1Uqk+d6O1f18U=
|
||||
github.com/1f349/violet v0.0.10/go.mod h1:Uzu6I1pLBP5UEzcUCTQBbk/NTfI5TAABSrowa8DSpR0=
|
||||
github.com/MrMelon54/exit-reload v0.0.1 h1:sxHa59tNEQMcikwuX2+93lw6Vi1+R7oCRF8a0C3alXc=
|
||||
|
@ -5,35 +5,21 @@ import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/1f349/lavender/server/pages"
|
||||
"github.com/MrMelon54/mjwt/auth"
|
||||
"github.com/MrMelon54/mjwt/claims"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/google/uuid"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"golang.org/x/oauth2"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
pageParse, err := template.New("pages").Parse(flowPopupHtml)
|
||||
if err != nil {
|
||||
log.Fatal("flow.go: Failed to parse flow popup HTML:", err)
|
||||
}
|
||||
flowPopupTemplate = pageParse
|
||||
|
||||
pageParse, err = template.New("pages").Parse(flowCallbackHtml)
|
||||
if err != nil {
|
||||
log.Fatal("flow.go: Failed to parse flow callback HTML:", err)
|
||||
}
|
||||
flowCallbackTemplate = pageParse
|
||||
}
|
||||
|
||||
func (h *HttpServer) flowPopup(rw http.ResponseWriter, req *http.Request, _ httprouter.Params) {
|
||||
err := flowPopupTemplate.Execute(rw, map[string]any{
|
||||
err := pages.FlowTemplates.Execute(rw, map[string]any{
|
||||
"ServiceName": h.conf.ServiceName,
|
||||
"Origin": req.URL.Query().Get("origin"),
|
||||
})
|
||||
@ -57,7 +43,7 @@ func (h *HttpServer) flowPopupPost(rw http.ResponseWriter, req *http.Request, _
|
||||
}
|
||||
|
||||
// save state for use later
|
||||
state := login.Config.Namespace + "%" + uuid.NewString()
|
||||
state := login.Config.Namespace + ":" + uuid.NewString()
|
||||
h.flowState.Set(state, flowStateData{
|
||||
login,
|
||||
targetOrigin,
|
||||
@ -79,7 +65,7 @@ func (h *HttpServer) flowCallback(rw http.ResponseWriter, req *http.Request, _ h
|
||||
|
||||
q := req.URL.Query()
|
||||
state := q.Get("state")
|
||||
n := strings.IndexByte(state, '%')
|
||||
n := strings.IndexByte(state, ':')
|
||||
if !h.manager.CheckNamespace(state[:n]) {
|
||||
http.Error(rw, "Invalid state", http.StatusBadRequest)
|
||||
return
|
||||
@ -146,7 +132,7 @@ func (h *HttpServer) flowCallback(rw http.ResponseWriter, req *http.Request, _ h
|
||||
return
|
||||
}
|
||||
|
||||
_ = flowCallbackTemplate.Execute(rw, map[string]any{
|
||||
_ = pages.FlowTemplates.Execute(rw, map[string]any{
|
||||
"ServiceName": h.conf.ServiceName,
|
||||
"TargetOrigin": v.targetOrigin,
|
||||
"TargetMessage": v3,
|
||||
|
@ -3,18 +3,26 @@ package pages
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"github.com/1f349/overlapfs"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed pages/*
|
||||
//go:embed *.go.html
|
||||
flowPages embed.FS
|
||||
flowTemplates *template.Template
|
||||
FlowTemplates *template.Template
|
||||
)
|
||||
|
||||
func LoadPages(wd string) {
|
||||
wdFs := os.DirFS(wd)
|
||||
|
||||
flowPages.Open()
|
||||
func LoadPages(wd string) error {
|
||||
wwwDir := filepath.Join(wd, "www")
|
||||
err := os.Mkdir(wwwDir, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
wdFs := os.DirFS(wwwDir)
|
||||
o := overlapfs.OverlapFS{A: flowPages, B: wdFs}
|
||||
FlowTemplates, err = template.ParseFS(o, "*.go.html")
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user