summaryrefslogtreecommitdiff
path: root/csrf.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-03 20:53:17 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-03 20:53:17 +0200
commit986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e (patch)
treef0198af6854ca4c3b13495eb8e3feb5788251a44 /csrf.go
parent3234c5ec777117d429bdc04dcf10c30094079e57 (diff)
downloadgosten-986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e.tar.gz
gosten-986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e.tar.bz2
gosten-986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e.zip
Fix CSRF handling, esp. when errors occur in form
Diffstat (limited to 'csrf.go')
-rw-r--r--csrf.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/csrf.go b/csrf.go
index 962a2a0..4539825 100644
--- a/csrf.go
+++ b/csrf.go
@@ -19,9 +19,13 @@ func csrfHandler(next http.Handler) http.Handler {
// Csrf handles the CSRF data for a form.
// Include it verbatim and then use `{{.CsrfField}}` in templates.
type Csrf struct {
- CsrfField template.HTML `form:"-"`
+ CsrfField template.HTML `form:"-" schema:"-"`
}
-func CsrfField(r *http.Request) Csrf {
- return Csrf{CsrfField: csrf.TemplateField(r)}
+func (c *Csrf) SetCsrfField(r *http.Request) {
+ c.CsrfField = csrf.TemplateField(r)
+}
+
+type WithCsrf interface {
+ SetCsrfField(r *http.Request)
}