Update URL routes
This commit is contained in:
parent
dab7a5c4ae
commit
b3039768af
21 changed files with 152 additions and 96 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package cli
|
||||
|
||||
// ===========================================================================================================
|
||||
// This file was generated automatically at 02-01-2023 12:34:04 using gogenlicense.
|
||||
// This file was generated automatically at 03-01-2023 11:39:55 using gogenlicense.
|
||||
// Do not edit manually, as changes may be overwritten.
|
||||
// ===========================================================================================================
|
||||
|
||||
|
|
@ -2133,7 +2133,7 @@ package cli
|
|||
// # Generation
|
||||
//
|
||||
// This variable and the associated documentation have been automatically generated using the 'gogenlicense' tool.
|
||||
// It was last updated at 02-01-2023 12:34:04.
|
||||
// It was last updated at 03-01-2023 11:39:55.
|
||||
var LegalNotices string
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ var (
|
|||
_ component.Routeable = (*Auth)(nil)
|
||||
)
|
||||
|
||||
func (auth *Auth) Routes() []string { return []string{"/auth/"} }
|
||||
func (auth *Auth) Routes() []string { return []string{"/user/"} }
|
||||
|
||||
func (auth *Auth) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
|
||||
router := httprouter.New()
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func (auth *Auth) Protect(handler http.Handler, perm Permission) http.Handler {
|
|||
}
|
||||
|
||||
// redirect the user to the login endpoint, with the original URI as a return
|
||||
dest := "/auth/login?next=" + url.QueryEscape(r.URL.RequestURI())
|
||||
dest := "/user/login?next=" + url.QueryEscape(r.URL.RequestURI())
|
||||
http.Redirect(w, r, dest, http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ func (auth *Auth) authPassword(ctx context.Context) http.Handler {
|
|||
CSRF: auth.csrf.Get(nil),
|
||||
|
||||
RenderTemplate: passwordTemplate,
|
||||
RenderTemplateContext: auth.UserFormContext,
|
||||
|
||||
Validate: func(r *http.Request, values map[string]string) (struct{}, error) {
|
||||
old, passcode, new, new2 := values["old"], values["passcode"], values["new"], values["new2"]
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}Distillery User{{ end }}
|
||||
{{ define "title" }}User{{ end }}
|
||||
|
||||
{{ define "header/time" }}
|
||||
<!-- no header/time -->
|
||||
{{ end }}
|
||||
{{ define "header"}}
|
||||
<!-- no header -->
|
||||
<p>
|
||||
<a class="pure-button pure-button-primary" href="/user/">{{ .User.User }}</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button pure-button-small" href="/user/logout/">Logout</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
<div class="pure-u-1">
|
||||
Welcome {{ .User.User }}!
|
||||
<a class="pure-button pure-button-small" href="/auth/logout/">Logout</a>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
<div class="pure-u-1">
|
||||
<p>
|
||||
{{ if .User.Admin }}
|
||||
|
|
@ -29,11 +25,11 @@
|
|||
{{ end }}
|
||||
</p>
|
||||
<div class="pure-button-group" role="group" role="Actions">
|
||||
<a class="pure-button" href="/auth/password/">Change Password</a>
|
||||
<a class="pure-button" href="/user/password/">Change Password</a>
|
||||
{{ if .User.TOTPEnabled }}
|
||||
<a class="pure-button" href="/auth/totp/disable/">Disable TOTP</a>
|
||||
<a class="pure-button" href="/user/totp/disable/">Disable TOTP</a>
|
||||
{{ else }}
|
||||
<a class="pure-button" href="/auth/totp/enable/">Enable TOTP</a>
|
||||
<a class="pure-button" href="/user/totp/enable/">Enable TOTP</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
<hr />
|
||||
|
|
@ -43,11 +39,13 @@
|
|||
<div class="pure-u-1">
|
||||
{{ if (not .User.TOTPEnabled) }}
|
||||
<div>
|
||||
<p class="error-message">
|
||||
TOTP is required to access these.
|
||||
</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div class="pure-button-group" role="group" role="Actions">
|
||||
<a class="pure-button" href="/dis/">Distillery Control Page</a>
|
||||
<a class="pure-button" href="/admin/">Distillery Admin Page</a>
|
||||
</div>
|
||||
<hr />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
{{ template "_form.html" . }}
|
||||
{{ define "form/title" }}Change Password{{ end }}
|
||||
{{ define "form/button" }}Update{{ end }}
|
||||
{{ define "form/extra" }}
|
||||
<div>
|
||||
<a class="pure-button" href="/auth/">Back</a>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button" href="/user/">{{ .User.User }}</a> >
|
||||
<a class="pure-button pure-button-primary" href="/user/password/">Change Password</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button pure-button-small" href="/user/logout/">Logout</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
{{ template "_form.html" . }}
|
||||
{{ define "form/title" }}Disable TOTP{{ end }}
|
||||
{{ define "form/button" }}Disable{{ end }}
|
||||
{{ define "form/extra" }}
|
||||
<div>
|
||||
<a class="pure-button" href="/auth/">Back</a>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button" href="/user/">{{ .User.User }}</a> >
|
||||
<a class="pure-button pure-button-primary" href="/user/totp/disable/">Disable TOTP</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button pure-button-small" href="/user/logout/">Logout</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
{{ define "form/inside" }}
|
||||
<div>
|
||||
<ul>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
{{ template "_form.html" . }}
|
||||
{{ define "form/title" }}Enable TOTP{{ end }}
|
||||
{{ define "form/button" }}Enable{{ end }}
|
||||
{{ define "form/extra" }}
|
||||
<div>
|
||||
<a class="pure-button" href="/auth/">Back</a>
|
||||
<hr />
|
||||
</div>
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button" href="/user/">{{ .User.User }}</a> >
|
||||
<a class="pure-button pure-button-primary" href="/user/totp/enable/">Enable TOTP</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button pure-button-small" href="/user/logout/">Logout</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
{{ define "form/inside" }}
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
{{ template "_form.html" . }}
|
||||
{{ define "form/title" }}Enable TOTP{{ end }}
|
||||
{{ define "form/button" }}Enable{{ end }}
|
||||
{{ define "form/extra" }}
|
||||
<div>
|
||||
<a class="pure-button" href="/auth/">Back</a>
|
||||
<hr />
|
||||
</div>
|
||||
{{ define "header" }}
|
||||
<p>
|
||||
<a class="pure-button" href="/user/">{{ .User.User }}</a> >
|
||||
<a class="pure-button pure-button-primary" href="/user/totp/enroll/">Enroll TOTP</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button pure-button-small" href="/user/logout/">Logout</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
{{ define "form/inside" }}
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ func (auth *Auth) authTOTPEnable(ctx context.Context) http.Handler {
|
|||
user, err := auth.UserOf(r)
|
||||
return struct{}{}, err == nil && user != nil && user.TOTPEnabled
|
||||
},
|
||||
|
||||
RenderTemplate: totpEnableTemplate,
|
||||
RenderTemplateContext: auth.UserFormContext,
|
||||
|
||||
Validate: func(r *http.Request, values map[string]string) (struct{}, error) {
|
||||
password := values["password"]
|
||||
|
|
@ -55,7 +57,7 @@ func (auth *Auth) authTOTPEnable(ctx context.Context) http.Handler {
|
|||
},
|
||||
|
||||
RenderSuccess: func(_ struct{}, values map[string]string, w http.ResponseWriter, r *http.Request) error {
|
||||
http.Redirect(w, r, "/auth/totp/enroll", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/user/totp/enroll", http.StatusSeeOther)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
@ -66,7 +68,7 @@ var totpEnrollStr string
|
|||
var totpEnrollTemplate = static.AssetsAuthLogin.MustParseShared("totp_enroll.html", totpEnrollStr)
|
||||
|
||||
type totpEnrollContext struct {
|
||||
httpx.FormContext
|
||||
userFormContext
|
||||
TOTPImage template.URL
|
||||
TOTPURL template.URL
|
||||
}
|
||||
|
|
@ -86,11 +88,16 @@ func (auth *Auth) authTOTPEnroll(ctx context.Context) http.Handler {
|
|||
return struct{}{}, user != nil && user.TOTPEnabled
|
||||
},
|
||||
RenderForm: func(context httpx.FormContext, w http.ResponseWriter, r *http.Request) {
|
||||
user, err := auth.UserOf(r)
|
||||
|
||||
ctx := totpEnrollContext{
|
||||
userFormContext: userFormContext{
|
||||
FormContext: context,
|
||||
},
|
||||
}
|
||||
|
||||
if user, err := auth.UserOf(r); err == nil && user != nil {
|
||||
if err == nil && user != nil {
|
||||
ctx.userFormContext.User = &user.User
|
||||
secret, err := user.TOTP()
|
||||
if err == nil {
|
||||
img, _ := TOTPLink(secret, 500, 500)
|
||||
|
|
@ -127,7 +134,7 @@ func (auth *Auth) authTOTPEnroll(ctx context.Context) http.Handler {
|
|||
},
|
||||
|
||||
RenderSuccess: func(_ struct{}, values map[string]string, w http.ResponseWriter, r *http.Request) error {
|
||||
http.Redirect(w, r, "/auth/", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/user/", http.StatusSeeOther)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
@ -152,6 +159,7 @@ func (auth *Auth) authTOTPDisable(ctx context.Context) http.Handler {
|
|||
return struct{}{}, user != nil && !user.TOTPEnabled
|
||||
},
|
||||
RenderTemplate: totpDisableTemplate,
|
||||
RenderTemplateContext: auth.UserFormContext,
|
||||
|
||||
Validate: func(r *http.Request, values map[string]string) (struct{}, error) {
|
||||
password, passcode := values["password"], values["passcode"]
|
||||
|
|
@ -178,7 +186,7 @@ func (auth *Auth) authTOTPDisable(ctx context.Context) http.Handler {
|
|||
},
|
||||
|
||||
RenderSuccess: func(_ struct{}, values map[string]string, w http.ResponseWriter, r *http.Request) error {
|
||||
http.Redirect(w, r, "/auth/", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/user/", http.StatusSeeOther)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"image/png"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||
"github.com/pquerna/otp"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
|
@ -288,3 +290,18 @@ func (au *AuthUser) Delete(ctx context.Context) error {
|
|||
|
||||
return table.Delete(&au.User).Error
|
||||
}
|
||||
|
||||
type userFormContext struct {
|
||||
httpx.FormContext
|
||||
User *models.User
|
||||
}
|
||||
|
||||
func (au *Auth) UserFormContext(ctx httpx.FormContext, r *http.Request) any {
|
||||
user, err := au.UserOf(r)
|
||||
|
||||
uctx := userFormContext{FormContext: ctx}
|
||||
if err == nil {
|
||||
uctx.User = &user.User
|
||||
}
|
||||
return uctx
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}Distillery Control Page - Components Page{{ end }}
|
||||
{{ define "title" }}Distillery Admin - Components Page{{ end }}
|
||||
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button" href="/dis/index">Control</a> >
|
||||
<a class="pure-button pure-button-primary" href="/dis/components">Components</a>
|
||||
<a class="pure-button" href="/admin/index">Admin</a> >
|
||||
<a class="pure-button pure-button-primary" href="/admin/components">Components</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}Distillery Control Page{{ end }}
|
||||
{{ define "title" }}Distillery Admin{{ end }}
|
||||
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button pure-button-primary" href="/dis/index">Control</a>
|
||||
<a class="pure-button pure-button-primary" href="/admin/index">Admin</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button" href="/dis/components">Components</a>
|
||||
<a class="pure-button" href="/admin/components">Components</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
|
|
@ -269,7 +269,7 @@
|
|||
<p>
|
||||
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">{{.URL}}</a><br>
|
||||
|
||||
<a class="pure-button" href="/dis/instance/{{.Slug}}">Details</a>
|
||||
<a class="pure-button" href="/admin/instance/{{.Slug}}">Details</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}Distillery Control Page - {{ .Instance.Slug }} - Ingredients{{ end }}
|
||||
{{ define "title" }}Distillery Admin - {{ .Instance.Slug }} - Ingredients{{ end }}
|
||||
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button" href="/dis/index">Control</a> >
|
||||
<a class="pure-button" href="/dis/instance/{{ .Instance.Slug }}">Instance</a> >
|
||||
<a class="pure-button pure-button-primary" href="/dis/ingredients/{{ .Instance.Slug }}">Ingredients</a>
|
||||
<a class="pure-button" href="/admin/index">Admin</a> >
|
||||
<a class="pure-button" href="/admin/instance/{{ .Instance.Slug }}">Instance</a> >
|
||||
<a class="pure-button pure-button-primary" href="/admin/ingredients/{{ .Instance.Slug }}">Ingredients</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}Distillery Control Page - {{ .Info.Slug }}{{ end }}
|
||||
{{ define "title" }}Distillery Admin - {{ .Info.Slug }}{{ end }}
|
||||
|
||||
{{ define "header"}}
|
||||
<p>
|
||||
<a class="pure-button" href="/dis/index">Control</a> >
|
||||
<a class="pure-button pure-button-primary" href="/dis/instance/{{ .Info.Slug }}">Instance</a>
|
||||
<a class="pure-button" href="/admin/index">Control</a> >
|
||||
<a class="pure-button pure-button-primary" href="/admin/instance/{{ .Info.Slug }}">Instance</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="pure-button" href="/dis/ingredients/{{ .Info.Slug }}">Ingredients</a>
|
||||
<a class="pure-button" href="/admin/ingredients/{{ .Info.Slug }}">Ingredients</a>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
|
|
@ -247,7 +247,7 @@
|
|||
<code class="date">{{ $user.Login.Time.Format "2006-01-02T15:04:05Z07:00" }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<form action="/dis/api/login" method="POST" target="_blank">
|
||||
<form action="/admin/api/login" method="POST" target="_blank">
|
||||
<input type="hidden" name="slug" value="{{ $slug }}">
|
||||
<input type="hidden" name="user" value="{{ $user.Name }}">
|
||||
<input type="submit" class="pure-button pure-button-action" value="Login in new window">
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ var (
|
|||
_ component.Routeable = (*Info)(nil)
|
||||
)
|
||||
|
||||
func (*Info) Routes() []string { return []string{"/dis/"} }
|
||||
func (*Info) Routes() []string { return []string{"/admin/"} }
|
||||
|
||||
func (info *Info) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
||||
|
||||
|
|
|
|||
|
|
@ -5,47 +5,47 @@ package static
|
|||
// AssetsHomeHome contains assets for the 'HomeHome' entrypoint.
|
||||
var AssetsHomeHome = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/HomeHome.2353e048.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/HomeHome.2353e048.css">`,
|
||||
}
|
||||
|
||||
// AssetsComponentsIndex contains assets for the 'ComponentsIndex' entrypoint.
|
||||
var AssetsComponentsIndex = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/ComponentsIndex.38d394c2.js"></script><script src="/static/ComponentsIndex.38d394c2.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/ComponentsIndex.38d394c2.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/ComponentsIndex.38d394c2.css">`,
|
||||
}
|
||||
|
||||
// AssetsControlIndex contains assets for the 'ControlIndex' entrypoint.
|
||||
var AssetsControlIndex = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/ControlIndex.a72fc239.js"></script><script src="/static/ControlIndex.75d2a312.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/ControlIndex.6d59e220.css"><link rel="stylesheet" href="/static/ControlIndex.6d2ae968.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/ControlIndex.6d59e220.css"><link rel="stylesheet" href="/static/ControlIndex.6d2ae968.css">`,
|
||||
}
|
||||
|
||||
// AssetsControlInstance contains assets for the 'ControlInstance' entrypoint.
|
||||
var AssetsControlInstance = Assets{
|
||||
Scripts: `<script nomodule="" defer src="/static/ControlIndex.75d2a312.js"></script><script type="module" src="/static/ControlIndex.a72fc239.js"></script><script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/ControlInstance.66b95713.js"></script><script src="/static/ControlInstance.9cc7166d.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/ControlIndex.6d59e220.css"><link rel="stylesheet" href="/static/ControlIndex.6d2ae968.css"><link rel="stylesheet" href="/static/ControlInstance.38d394c2.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/ControlIndex.6d59e220.css"><link rel="stylesheet" href="/static/ControlIndex.6d2ae968.css"><link rel="stylesheet" href="/static/ControlInstance.38d394c2.css">`,
|
||||
}
|
||||
|
||||
// AssetsInstanceComponentsIndex contains assets for the 'InstanceComponentsIndex' entrypoint.
|
||||
var AssetsInstanceComponentsIndex = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/InstanceComponentsIndex.38d394c2.js"></script><script src="/static/InstanceComponentsIndex.38d394c2.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/InstanceComponentsIndex.38d394c2.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/InstanceComponentsIndex.38d394c2.css">`,
|
||||
}
|
||||
|
||||
// AssetsAuthLogin contains assets for the 'AuthLogin' entrypoint.
|
||||
var AssetsAuthLogin = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/AuthLogin.38d394c2.js"></script><script src="/static/AuthLogin.38d394c2.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/AuthLogin.38d394c2.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/AuthLogin.38d394c2.css">`,
|
||||
}
|
||||
|
||||
// AssetsAuthHome contains assets for the 'AuthHome' entrypoint.
|
||||
var AssetsAuthHome = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/AuthHome.38d394c2.js"></script><script src="/static/AuthHome.38d394c2.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/AuthHome.38d394c2.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/AuthHome.38d394c2.css">`,
|
||||
}
|
||||
|
||||
// AssetsAuthTOTP contains assets for the 'AuthTOTP' entrypoint.
|
||||
var AssetsAuthTOTP = Assets{
|
||||
Scripts: `<script type="module" src="/static/HomeHome.38d394c2.js"></script><script src="/static/HomeHome.38d394c2.js" nomodule="" defer></script><script type="module" src="/static/AuthTOTP.38d394c2.js"></script><script src="/static/AuthTOTP.38d394c2.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.25c6db8a.css"><link rel="stylesheet" href="/static/AuthTOTP.38d394c2.css">`,
|
||||
Styles: `<link rel="stylesheet" href="/static/HomeHome.4ec77c43.css"><link rel="stylesheet" href="/static/AuthTOTP.38d394c2.css">`,
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -64,3 +64,10 @@ footer {
|
|||
.pure-button-xlarge {
|
||||
font-size: 125%;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background-color: pink;
|
||||
border: 1px solid red;
|
||||
padding: 2px;
|
||||
color: red;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,27 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}{{ block "form/title" . }}Form{{ end }}{{ end }}
|
||||
|
||||
{{ define "header/time" }}
|
||||
<!-- no header/time -->
|
||||
{{ end }}
|
||||
{{ define "header"}}
|
||||
<!-- no header -->
|
||||
{{ end }}
|
||||
|
||||
{{ define "header" }}<!-- no header -->{{ end }}
|
||||
{{ define "header/time" }}<!-- no time -->{{ end }}
|
||||
{{ define "content" }}
|
||||
<div class="pure-u-1">
|
||||
|
||||
{{ block "form/message" . }}
|
||||
{{ $E := .Error }}
|
||||
{{ if not (eq $E "") }}
|
||||
<div>
|
||||
{{ $E }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ block "form/extra" . }}<!-- no extra -->{{ end }}
|
||||
|
||||
<form class="pure-form pure-form-aligned" method="POST">
|
||||
<fieldset>
|
||||
<legend>{{ template "form/title" . }}</legend>
|
||||
|
||||
{{ block "form/message" . }}
|
||||
{{ $E := .Error }}
|
||||
{{ if not (eq $E "") }}
|
||||
<div class="pure-form-group">
|
||||
<p class="error-message">
|
||||
{{ $E }}
|
||||
</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ block "form/inside" . }}<!-- no inside -->{{ end }}
|
||||
{{ .Form }}
|
||||
<input type="submit" value="{{ block " form/button" .}}Submit{{ end }}" class="pure-button">
|
||||
|
|
|
|||
|
|
@ -44,9 +44,13 @@ type Form[D any] struct {
|
|||
RenderForm func(context FormContext, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
// RenderTemplate represents an optional form to display to the user when RenderForm is nil
|
||||
// It is passed a [FormContext] instance.
|
||||
// It is passed the return value of [RenderTemplateContext], or a [FormContext] instance if this does not exist.
|
||||
RenderTemplate *template.Template
|
||||
|
||||
// RenderTemplateContext is the context to be used for RenderTemplate.
|
||||
// When nil, assumed to be the identify function
|
||||
RenderTemplateContext func(ctx FormContext, r *http.Request) any
|
||||
|
||||
// Validate, if non-nil, validates the given submitted values.
|
||||
// There is no guarantee that the values are set.
|
||||
Validate func(r *http.Request, values map[string]string) (D, error)
|
||||
|
|
@ -151,8 +155,16 @@ func (form *Form[D]) renderForm(err error, values map[string]string, w http.Resp
|
|||
panic("form.RenderForm and form.Form are nil")
|
||||
}
|
||||
|
||||
// get the template context
|
||||
var tplctx any
|
||||
if form.RenderTemplateContext == nil {
|
||||
tplctx = ctx
|
||||
} else {
|
||||
tplctx = form.RenderTemplateContext(ctx, r)
|
||||
}
|
||||
|
||||
// render the form
|
||||
WriteHTML(ctx, nil, form.RenderTemplate, "", w, r)
|
||||
WriteHTML(tplctx, nil, form.RenderTemplate, "", w, r)
|
||||
}
|
||||
|
||||
// FormContext is passed to Form.Form when used
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue