From 986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 3 Oct 2024 20:53:17 +0200 Subject: Fix CSRF handling, esp. when errors occur in form --- csrf.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'csrf.go') 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) } -- cgit v1.2.3-70-g09d2