feat(api): localize console pages and api error messages

The language comes from the user setting, then the lang cookie, then
Accept-Language, falling back to English. Errors keep a stable code and
carry a translated message.

Closes #42

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:07:00 +01:00
1 parent dde7b890b8
commit 70190446ff
12 files changed
+690 -203

No files matched your search

+7 -6
View File
@@ -8,8 +8,8 @@ import (
"time" "time"
"git.zb-server.de/ZB-Server/uptimesebi/internal/api" "git.zb-server.de/ZB-Server/uptimesebi/internal/api"
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config" "git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/migrations" "git.zb-server.de/ZB-Server/uptimesebi/internal/migrations"
"git.zb-server.de/ZB-Server/uptimesebi/internal/platform" "git.zb-server.de/ZB-Server/uptimesebi/internal/platform"
"git.zb-server.de/ZB-Server/uptimesebi/internal/sealed" "git.zb-server.de/ZB-Server/uptimesebi/internal/sealed"
@@ -54,15 +54,16 @@ func run(log *slog.Logger, args []string) error {
} }
defer deps.Close() defer deps.Close()
srv := api.New(cfg, log, tenant.New(deps.DB), deps.Redis, keys) catalog, err := i18n.Load()
if err != nil {
return err
}
srv := api.New(cfg, api.Deps{Log: log, DB: tenant.New(deps.DB), Redis: deps.Redis, Keys: keys, Catalog: catalog})
health := platform.NewHealth(deps.Probes()) health := platform.NewHealth(deps.Probes())
r := platform.NewRouter(log) r := platform.NewRouter(log)
health.Register(r) health.Register(r)
r.StaticFS("/static", web.Static()) r.StaticFS("/static", web.Static())
srv.Mount(r)
app := r.Group("/", srv.Sessions().Load(), auth.CSRF())
srv.Register(app)
srv.RegisterPages(app)
return platform.Serve(ctx, log, platform.NewHTTPServer(cfg.Listen, r), health, 5*time.Second, cfg.ShutdownTimeout) return platform.Serve(ctx, log, platform.NewHTTPServer(cfg.Listen, r), health, 5*time.Second, cfg.ShutdownTimeout)
} }
+24 -16
View File
@@ -16,6 +16,7 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth" "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config" "git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store" "git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
) )
@@ -46,12 +47,12 @@ func (s *Server) signup(c *gin.Context) {
internalError(c, err) internalError(c, err)
return return
} else if !allowed { } else if !allowed {
fail(c, http.StatusForbidden, "signup_closed", "Registrierung ist deaktiviert.") fail(c, http.StatusForbidden, "signup_closed")
return return
} }
hash, err := auth.HashPassword(req.Password) hash, err := auth.HashPassword(req.Password)
if errors.Is(err, auth.ErrPasswordTooShort) { if errors.Is(err, auth.ErrPasswordTooShort) {
fail(c, http.StatusUnprocessableEntity, "password_too_short", err.Error()) fail(c, http.StatusUnprocessableEntity, "password_too_short", "Min", auth.MinPasswordLength)
return return
} else if err != nil { } else if err != nil {
internalError(c, err) internalError(c, err)
@@ -66,6 +67,7 @@ func (s *Server) signup(c *gin.Context) {
Email: normalizeEmail(req.Email), Email: normalizeEmail(req.Email),
DisplayName: strings.TrimSpace(req.DisplayName), DisplayName: strings.TrimSpace(req.DisplayName),
PasswordHash: &hash, PasswordHash: &hash,
Locale: ptr(i18n.Lang(ctx)),
}) })
if err != nil { if err != nil {
return err return err
@@ -77,19 +79,19 @@ func (s *Server) signup(c *gin.Context) {
}) })
switch { switch {
case isUniqueViolation(err, "users_email_key"): case isUniqueViolation(err, "users_email_key"):
fail(c, http.StatusConflict, "email_taken", "Diese E-Mail-Adresse ist bereits registriert.") fail(c, http.StatusConflict, "email_taken")
return return
case isUniqueViolation(err, "orgs_slug_key"): case isUniqueViolation(err, "orgs_slug_key"):
fail(c, http.StatusConflict, "slug_taken", "Dieser Kurzname ist bereits vergeben.") fail(c, http.StatusConflict, "slug_taken")
return return
case isCheckViolation(err): case isCheckViolation(err):
fail(c, http.StatusUnprocessableEntity, "invalid_input", "Kurzname: 2–63 Zeichen, a–z, 0–9 und Bindestrich.") fail(c, http.StatusUnprocessableEntity, "invalid_slug")
return return
case err != nil: case err != nil:
internalError(c, err) internalError(c, err)
return return
} }
s.startSession(c, user.ID, orgID) s.startSession(c, user.ID, orgID, i18n.Lang(ctx))
} }
func (s *Server) signupAllowed(ctx context.Context) (bool, error) { func (s *Server) signupAllowed(ctx context.Context) (bool, error) {
@@ -153,7 +155,7 @@ func (s *Server) login(c *gin.Context) {
} }
if user.TotpSecret != nil { if user.TotpSecret != nil {
token := randomToken() token := auth.RandomToken()
if err := s.rdb.Set(ctx, mfaKey(token), user.ID.String(), mfaTTL).Err(); err != nil { if err := s.rdb.Set(ctx, mfaKey(token), user.ID.String(), mfaTTL).Err(); err != nil {
internalError(c, err) internalError(c, err)
return return
@@ -177,7 +179,7 @@ func (s *Server) loginTOTP(c *gin.Context) {
ctx := c.Request.Context() ctx := c.Request.Context()
token, _ := c.Cookie(mfaCookie) token, _ := c.Cookie(mfaCookie)
if token == "" { if token == "" {
fail(c, http.StatusUnauthorized, "mfa_expired", "Anmeldung abgelaufen, bitte erneut anmelden.") fail(c, http.StatusUnauthorized, "mfa_expired")
return return
} }
if !s.limit(c, "mfa:"+mfaKey(token), 5, mfaTTL) { if !s.limit(c, "mfa:"+mfaKey(token), 5, mfaTTL) {
@@ -185,7 +187,7 @@ func (s *Server) loginTOTP(c *gin.Context) {
} }
raw, err := s.rdb.Get(ctx, mfaKey(token)).Result() raw, err := s.rdb.Get(ctx, mfaKey(token)).Result()
if err != nil { if err != nil {
fail(c, http.StatusUnauthorized, "mfa_expired", "Anmeldung abgelaufen, bitte erneut anmelden.") fail(c, http.StatusUnauthorized, "mfa_expired")
return return
} }
userID, err := uuid.Parse(raw) userID, err := uuid.Parse(raw)
@@ -199,7 +201,7 @@ func (s *Server) loginTOTP(c *gin.Context) {
return return
} }
if !ok { if !ok {
fail(c, http.StatusUnauthorized, "invalid_code", "Code ungültig.") fail(c, http.StatusUnauthorized, "invalid_code")
return return
} }
_ = s.rdb.Del(ctx, mfaKey(token)).Err() _ = s.rdb.Del(ctx, mfaKey(token)).Err()
@@ -209,9 +211,15 @@ func (s *Server) loginTOTP(c *gin.Context) {
func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID) { func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID) {
ctx := c.Request.Context() ctx := c.Request.Context()
var orgs []store.ListUserOrgsRow var (
user store.User
orgs []store.ListUserOrgsRow
)
err := s.db.Tx(ctx, tenant.User(userID), func(q *store.Queries) error { err := s.db.Tx(ctx, tenant.User(userID), func(q *store.Queries) error {
var err error var err error
if user, err = q.GetUser(ctx, userID); err != nil {
return err
}
orgs, err = q.ListUserOrgs(ctx, userID) orgs, err = q.ListUserOrgs(ctx, userID)
return err return err
}) })
@@ -223,14 +231,14 @@ func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID) {
if len(orgs) > 0 { if len(orgs) > 0 {
org = orgs[0].ID org = orgs[0].ID
} }
s.startSession(c, userID, org) s.startSession(c, userID, org, deref(user.Locale))
} }
func (s *Server) startSession(c *gin.Context, userID, orgID uuid.UUID) { func (s *Server) startSession(c *gin.Context, userID, orgID uuid.UUID, locale string) {
if old := auth.Current(c); old != nil { if old := auth.Current(c); old != nil {
_ = s.sessions.Delete(c.Request.Context(), old) _ = s.sessions.Delete(c.Request.Context(), old)
} }
sess, err := s.sessions.Create(c.Request.Context(), userID, orgID) sess, err := s.sessions.Create(c.Request.Context(), userID, orgID, locale)
if err != nil { if err != nil {
internalError(c, err) internalError(c, err)
return return
@@ -271,7 +279,7 @@ func (s *Server) limit(c *gin.Context, key string, n int, window time.Duration)
} }
if !ok { if !ok {
c.Header("Retry-After", "60") c.Header("Retry-After", "60")
fail(c, http.StatusTooManyRequests, "rate_limited", "Zu viele Versuche, bitte später erneut.") fail(c, http.StatusTooManyRequests, "rate_limited")
return false return false
} }
return true return true
@@ -285,7 +293,7 @@ func mfaKey(token string) string {
func normalizeEmail(e string) string { return strings.ToLower(strings.TrimSpace(e)) } func normalizeEmail(e string) string { return strings.ToLower(strings.TrimSpace(e)) }
func invalidCredentials(c *gin.Context) { func invalidCredentials(c *gin.Context) {
fail(c, http.StatusUnauthorized, "invalid_credentials", "E-Mail oder Passwort falsch.") fail(c, http.StatusUnauthorized, "invalid_credentials")
} }
func isUniqueViolation(err error, constraint string) bool { func isUniqueViolation(err error, constraint string) bool {
+7 -7
View File
@@ -96,7 +96,7 @@ func (s *Server) switchOrg(c *gin.Context) {
return return
} }
} }
fail(c, http.StatusNotFound, "org_not_found", "Organisation nicht gefunden.") fail(c, http.StatusNotFound, "org_not_found")
} }
func totpSetupKey(user uuid.UUID) string { return "totp_setup:" + user.String() } func totpSetupKey(user uuid.UUID) string { return "totp_setup:" + user.String() }
@@ -109,7 +109,7 @@ func (s *Server) totpSetup(c *gin.Context) {
return return
} }
if me.TOTP { if me.TOTP {
fail(c, http.StatusConflict, "totp_already_enabled", "TOTP ist bereits aktiv.") fail(c, http.StatusConflict, "totp_already_enabled")
return return
} }
key, err := auth.NewTOTPKey(me.Email) key, err := auth.NewTOTPKey(me.Email)
@@ -138,7 +138,7 @@ func (s *Server) totpEnable(c *gin.Context) {
sess := auth.Current(c) sess := auth.Current(c)
secret, err := s.rdb.Get(ctx, totpSetupKey(sess.UserID)).Result() secret, err := s.rdb.Get(ctx, totpSetupKey(sess.UserID)).Result()
if err != nil { if err != nil {
fail(c, http.StatusConflict, "totp_setup_expired", "Einrichtung abgelaufen, bitte neu starten.") fail(c, http.StatusConflict, "totp_setup_expired")
return return
} }
if !s.limit(c, "totp_enable:"+sess.UserID.String(), 10, totpSetupTTL) { if !s.limit(c, "totp_enable:"+sess.UserID.String(), 10, totpSetupTTL) {
@@ -150,7 +150,7 @@ func (s *Server) totpEnable(c *gin.Context) {
return return
} }
if !ok { if !ok {
fail(c, http.StatusUnprocessableEntity, "invalid_code", "Code ungültig.") fail(c, http.StatusUnprocessableEntity, "invalid_code")
return return
} }
sealedSecret := s.keys.Seal([]byte(secret), sess.UserID[:]) sealedSecret := s.keys.Seal([]byte(secret), sess.UserID[:])
@@ -187,7 +187,7 @@ func (s *Server) totpDisable(c *gin.Context) {
} }
for _, o := range me.Orgs { for _, o := range me.Orgs {
if o.RequireTOTP { if o.RequireTOTP {
fail(c, http.StatusConflict, "totp_required_by_org", "Eine deiner Organisationen verlangt TOTP.") fail(c, http.StatusConflict, "totp_required_by_org")
return return
} }
} }
@@ -202,7 +202,7 @@ func (s *Server) totpDisable(c *gin.Context) {
return return
} }
if user.PasswordHash == nil { if user.PasswordHash == nil {
fail(c, http.StatusConflict, "no_password", "Konto ohne Passwort.") fail(c, http.StatusConflict, "no_password")
return return
} }
if ok, _, err := auth.VerifyPassword(*user.PasswordHash, req.Password); err != nil || !ok { if ok, _, err := auth.VerifyPassword(*user.PasswordHash, req.Password); err != nil || !ok {
@@ -213,7 +213,7 @@ func (s *Server) totpDisable(c *gin.Context) {
internalError(c, err) internalError(c, err)
return return
} else if !ok { } else if !ok {
fail(c, http.StatusUnauthorized, "invalid_code", "Code ungültig.") fail(c, http.StatusUnauthorized, "invalid_code")
return return
} }
err = s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error { err = s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error {
+9 -9
View File
@@ -10,15 +10,15 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/web" "git.zb-server.de/ZB-Server/uptimesebi/internal/web"
) )
func (s *Server) RegisterPages(r gin.IRouter) { func (s *Server) registerPages(r gin.IRouter) {
r.GET("/login", s.loginPage) r.GET("/login", s.loginPage)
r.GET("/signup", s.signupPage) r.GET("/signup", s.signupPage)
r.GET("/", s.page("Übersicht", web.Dashboard)) r.GET("/", s.page("console.monitors.title", web.Dashboard))
r.GET("/settings/security", s.page("Sicherheit", web.Security)) r.GET("/settings/security", s.page("security.title", web.Security))
} }
func pageFor(c *gin.Context, title string) web.Page { func (s *Server) pageFor(c *gin.Context, titleID string) web.Page {
p := web.Page{Title: title} p := web.Page{TitleID: titleID, Languages: s.catalog.Supported()}
if sess := auth.Current(c); sess != nil { if sess := auth.Current(c); sess != nil {
p.CSRF = sess.CSRF p.CSRF = sess.CSRF
} }
@@ -35,7 +35,7 @@ func (s *Server) loginPage(c *gin.Context) {
internalError(c, err) internalError(c, err)
return return
} }
web.Render(c, http.StatusOK, web.Login(pageFor(c, "Anmelden"), allowed)) web.Render(c, http.StatusOK, web.Login(s.pageFor(c, "auth.login.title"), allowed))
} }
func (s *Server) signupPage(c *gin.Context) { func (s *Server) signupPage(c *gin.Context) {
@@ -48,10 +48,10 @@ func (s *Server) signupPage(c *gin.Context) {
c.Redirect(http.StatusSeeOther, "/login") c.Redirect(http.StatusSeeOther, "/login")
return return
} }
web.Render(c, http.StatusOK, web.Signup(pageFor(c, "Konto anlegen"))) web.Render(c, http.StatusOK, web.Signup(s.pageFor(c, "auth.signup.title")))
} }
func (s *Server) page(title string, view func(web.Page, web.Me) templ.Component) gin.HandlerFunc { func (s *Server) page(titleID string, view func(web.Page, web.Me) templ.Component) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
sess := auth.Current(c) sess := auth.Current(c)
if sess == nil { if sess == nil {
@@ -63,7 +63,7 @@ func (s *Server) page(title string, view func(web.Page, web.Me) templ.Component)
internalError(c, err) internalError(c, err)
return return
} }
web.Render(c, http.StatusOK, view(pageFor(c, title), toWebMe(me))) web.Render(c, http.StatusOK, view(s.pageFor(c, titleID), toWebMe(me)))
} }
} }
+104 -21
View File
@@ -1,3 +1,5 @@
// Package api serves the management JSON API under /api/v1 and the
// server-rendered console pages that call it.
package api package api
import ( import (
@@ -11,40 +13,58 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth" "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config" "git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/sealed" "git.zb-server.de/ZB-Server/uptimesebi/internal/sealed"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
) )
const localeCookie = "lang"
// Server holds the dependencies shared by all handlers.
type Server struct { type Server struct {
cfg config.API cfg config.API
log *slog.Logger log *slog.Logger
db *tenant.DB db *tenant.DB
rdb redis.UniversalClient rdb redis.UniversalClient
keys *sealed.Keyring keys *sealed.Keyring
catalog *i18n.Catalog
sessions *auth.Sessions sessions *auth.Sessions
limiter *auth.Limiter limiter *auth.Limiter
totp *auth.TOTPVerifier totp *auth.TOTPVerifier
} }
func New(cfg config.API, log *slog.Logger, db *tenant.DB, rdb redis.UniversalClient, keys *sealed.Keyring) *Server { // Deps are the external resources a Server needs.
type Deps struct {
Log *slog.Logger
DB *tenant.DB
Redis redis.UniversalClient
Keys *sealed.Keyring
Catalog *i18n.Catalog
}
// New returns a Server. It does not register any routes; see Mount.
func New(cfg config.API, d Deps) *Server {
return &Server{ return &Server{
cfg: cfg, cfg: cfg,
log: log, log: d.Log,
db: db, db: d.DB,
rdb: rdb, rdb: d.Redis,
keys: keys, keys: d.Keys,
sessions: auth.NewSessions(rdb, cfg.SessionIdle, cfg.SessionAbsolute), catalog: d.Catalog,
limiter: auth.NewLimiter(rdb), sessions: auth.NewSessions(d.Redis, cfg.SessionIdle, cfg.SessionAbsolute),
totp: auth.NewTOTPVerifier(rdb), limiter: auth.NewLimiter(d.Redis),
totp: auth.NewTOTPVerifier(d.Redis),
} }
} }
func (s *Server) Sessions() *auth.Sessions { return s.sessions } // Mount installs session loading, locale resolution and CSRF protection and
// registers the JSON API and the console pages below them.
func (s *Server) Mount(r gin.IRouter) {
g := r.Group("/", s.sessions.Load(), s.localize(), auth.CSRF())
// Register mounts the JSON API. The caller must already have installed v1 := g.Group("/api/v1")
// Sessions().Load() and auth.CSRF() on the engine. v1.POST("/locale", s.setLocale)
func (s *Server) Register(r gin.IRouter) {
v1 := r.Group("/api/v1")
a := v1.Group("/auth") a := v1.Group("/auth")
a.POST("/signup", s.signup) a.POST("/signup", s.signup)
@@ -58,6 +78,55 @@ func (s *Server) Register(r gin.IRouter) {
me.POST("/totp/setup", s.totpSetup) me.POST("/totp/setup", s.totpSetup)
me.POST("/totp/enable", s.totpEnable) me.POST("/totp/enable", s.totpEnable)
me.POST("/totp/disable", s.totpDisable) me.POST("/totp/disable", s.totpDisable)
s.registerPages(g)
}
// localize resolves the language from, in order: the signed-in user's
// setting, the lang cookie, and Accept-Language.
func (s *Server) localize() gin.HandlerFunc {
return func(c *gin.Context) {
var pref string
if sess := auth.Current(c); sess != nil {
pref = sess.Locale
}
cookie, _ := c.Cookie(localeCookie)
l := s.catalog.Match(pref, cookie, c.GetHeader("Accept-Language"))
c.Request = c.Request.WithContext(i18n.NewContext(c.Request.Context(), l))
c.Header("Content-Language", l.Lang())
c.Header("Vary", "Accept-Language, Cookie")
c.Next()
}
}
type localeRequest struct {
Locale string `json:"locale" binding:"required,max=10"`
}
func (s *Server) setLocale(c *gin.Context) {
var req localeRequest
if !bind(c, &req) {
return
}
if !s.catalog.IsSupported(req.Locale) {
fail(c, http.StatusUnprocessableEntity, "unsupported_locale")
return
}
ctx := c.Request.Context()
if sess := auth.Current(c); sess != nil {
err := s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error {
return q.SetUserLocale(ctx, store.SetUserLocaleParams{ID: sess.UserID, Locale: &req.Locale})
})
if err == nil {
err = s.sessions.SetLocale(ctx, sess, req.Locale)
}
if err != nil {
internalError(c, err)
return
}
}
setCookie(c, localeCookie, req.Locale, 365*24*3600)
c.Status(http.StatusNoContent)
} }
type apiError struct { type apiError struct {
@@ -66,18 +135,26 @@ type apiError struct {
Fields map[string]string `json:"fields,omitempty"` Fields map[string]string `json:"fields,omitempty"`
} }
func fail(c *gin.Context, status int, code, msg string) { // fail aborts with a machine-readable code and a message translated from
c.AbortWithStatusJSON(status, apiError{Error: code, Message: msg}) // the catalog entry "error.<code>". kv fills placeholders in that message.
func fail(c *gin.Context, status int, code string, kv ...any) {
c.AbortWithStatusJSON(status, apiError{
Error: code,
Message: i18n.T(c.Request.Context(), "error."+code, kv...),
})
} }
func internalError(c *gin.Context, err error) { func internalError(c *gin.Context, err error) {
_ = c.Error(err) _ = c.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, apiError{Error: "internal", Message: "Interner Fehler."}) fail(c, http.StatusInternalServerError, "internal")
} }
func bind(c *gin.Context, dst any) bool { func bind(c *gin.Context, dst any) bool {
if err := c.ShouldBindJSON(dst); err != nil { err := c.ShouldBindJSON(dst)
e := apiError{Error: "invalid_input", Message: "Eingaben prüfen."} if err == nil {
return true
}
e := apiError{Error: "invalid_input", Message: i18n.T(c.Request.Context(), "error.invalid_input")}
var ve validator.ValidationErrors var ve validator.ValidationErrors
if errors.As(err, &ve) { if errors.As(err, &ve) {
e.Fields = map[string]string{} e.Fields = map[string]string{}
@@ -88,8 +165,6 @@ func bind(c *gin.Context, dst any) bool {
c.AbortWithStatusJSON(http.StatusBadRequest, e) c.AbortWithStatusJSON(http.StatusBadRequest, e)
return false return false
} }
return true
}
func setCookie(c *gin.Context, name, value string, maxAge int) { func setCookie(c *gin.Context, name, value string, maxAge int) {
http.SetCookie(c.Writer, &http.Cookie{ http.SetCookie(c.Writer, &http.Cookie{
@@ -98,4 +173,12 @@ func setCookie(c *gin.Context, name, value string, maxAge int) {
}) })
} }
func randomToken() string { return auth.RandomToken() } func ptr[T any](v T) *T { return &v }
func deref[T any](p *T) T {
var zero T
if p == nil {
return zero
}
return *p
}
+7 -1
View File
@@ -8,7 +8,7 @@
window.api = api; window.api = api;
const message = (err) => const message = (err) =>
err.response?.data?.message ?? "Verbindung fehlgeschlagen."; err.response?.data?.message ?? document.body.dataset.msgNetwork;
const showError = (form, text) => { const showError = (form, text) => {
const el = form.querySelector("[data-error]"); const el = form.querySelector("[data-error]");
@@ -50,6 +50,12 @@
}); });
document.addEventListener("click", async (ev) => { document.addEventListener("click", async (ev) => {
const locale = ev.target.closest("[data-locale]");
if (locale) {
await api.post("/locale", { locale: locale.dataset.locale }).catch(() => {});
location.reload();
return;
}
if (ev.target.closest("[data-logout]")) { if (ev.target.closest("[data-logout]")) {
await api.post("/auth/logout").catch(() => {}); await api.post("/auth/logout").catch(() => {});
location.assign("/login"); location.assign("/login");
+23 -15
View File
@@ -1,37 +1,45 @@
package web package web
import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
templ Login(p Page, signupAllowed bool) { templ Login(p Page, signupAllowed bool) {
@authShell(p, "Anmelden") { @authShell(p) {
<form data-api="/auth/login" data-next="/"> <form data-api="/auth/login" data-next="/">
@formError() @formError()
<div data-step="password"> <div data-step="password">
@field("E-Mail", "email", "email", "username", true) @field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field("Passwort", "password", "password", "current-password", true) @field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
</div> </div>
<div data-step="totp" hidden> <div data-step="totp" hidden>
<p class="mb-4 text-sm text-muted">Code aus der Authenticator-App eingeben.</p> <p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "auth.login.totp_hint") }</p>
@field("Code", "code", "text", "one-time-code", false) @field(i18n.T(ctx, "auth.field.code"), "code", "text", "one-time-code", false)
</div> </div>
@submit("Weiter") @submit(i18n.T(ctx, "auth.login.submit"))
</form> </form>
if signupAllowed { if signupAllowed {
<p class="mt-8 text-sm text-muted">Noch kein Konto? <a class="text-ink underline underline-offset-2" href="/signup">Registrieren</a></p> <p class="mt-8 text-sm text-muted">
{ i18n.T(ctx, "auth.login.no_account") }
<a class="text-ink underline underline-offset-2" href="/signup">{ i18n.T(ctx, "auth.login.to_signup") }</a>
</p>
} }
} }
} }
templ Signup(p Page) { templ Signup(p Page) {
@authShell(p, "Konto anlegen") { @authShell(p) {
<form data-api="/auth/signup" data-next="/"> <form data-api="/auth/signup" data-next="/">
@formError() @formError()
@field("Name", "display_name", "text", "name", false) @field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false)
@field("E-Mail", "email", "email", "username", true) @field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field("Passwort (min. 12 Zeichen)", "password", "password", "new-password", true) @field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true)
<hr class="my-6 border-rule"/> <hr class="my-6 border-rule"/>
@field("Organisation", "org_name", "text", "organization", true) @field(i18n.T(ctx, "auth.field.org_name"), "org_name", "text", "organization", true)
@field("Kurzname (a–z, 0–9, -)", "org_slug", "text", "off", true) @field(i18n.T(ctx, "auth.field.org_slug"), "org_slug", "text", "off", true)
@submit("Anlegen") @submit(i18n.T(ctx, "auth.signup.submit"))
</form> </form>
<p class="mt-8 text-sm text-muted"><a class="text-ink underline underline-offset-2" href="/login">Zur Anmeldung</a></p> <p class="mt-8 text-sm text-muted"><a class="text-ink underline underline-offset-2" href="/login">{ i18n.T(ctx, "auth.signup.to_login") }</a></p>
} }
} }
+77 -20
View File
@@ -9,6 +9,11 @@ package web
import "github.com/a-h/templ" import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime" import templruntime "github.com/a-h/templ/runtime"
import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
func Login(p Page, signupAllowed bool) templ.Component { func Login(p Page, signupAllowed bool) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
@@ -50,43 +55,82 @@ func Login(p Page, signupAllowed bool) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("E-Mail", "email", "email", "username", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Passwort", "password", "password", "current-password", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</div><div data-step=\"totp\" hidden><p class=\"mb-4 text-sm text-muted\">Code aus der Authenticator-App eingeben.</p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</div><div data-step=\"totp\" hidden><p class=\"mb-4 text-sm text-muted\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Code", "code", "text", "one-time-code", false).Render(ctx, templ_7745c5c3_Buffer) var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.totp_hint"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 17, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = submit("Weiter").Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.code"), "code", "text", "one-time-code", false).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</form>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = submit(i18n.T(ctx, "auth.login.submit")).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</form>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if signupAllowed { if signupAllowed {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<p class=\"mt-8 text-sm text-muted\">Noch kein Konto? <a class=\"text-ink underline underline-offset-2\" href=\"/signup\">Registrieren</a></p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<p class=\"mt-8 text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.no_account"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 24, Col: 42}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " <a class=\"text-ink underline underline-offset-2\" href=\"/signup\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.to_signup"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 25, Col: 105}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</a></p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
return nil return nil
}) })
templ_7745c5c3_Err = authShell(p, "Anmelden").Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -111,7 +155,7 @@ func Signup(p Page) templ.Component {
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var4 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_Var7 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
@@ -123,7 +167,7 @@ func Signup(p Page) templ.Component {
}() }()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<form data-api=\"/auth/signup\" data-next=\"/\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<form data-api=\"/auth/signup\" data-next=\"/\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -131,41 +175,54 @@ func Signup(p Page) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Name", "display_name", "text", "name", false).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("E-Mail", "email", "email", "username", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Passwort (min. 12 Zeichen)", "password", "password", "new-password", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<hr class=\"my-6 border-rule\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<hr class=\"my-6 border-rule\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Organisation", "org_name", "text", "organization", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.org_name"), "org_name", "text", "organization", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Kurzname (a–z, 0–9, -)", "org_slug", "text", "off", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.org_slug"), "org_slug", "text", "off", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = submit("Anlegen").Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = submit(i18n.T(ctx, "auth.signup.submit")).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</form><p class=\"mt-8 text-sm text-muted\"><a class=\"text-ink underline underline-offset-2\" href=\"/login\">Zur Anmeldung</a></p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</form><p class=\"mt-8 text-sm text-muted\"><a class=\"text-ink underline underline-offset-2\" href=\"/login\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.signup.to_login"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 43, Col: 137}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</a></p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
return nil return nil
}) })
templ_7745c5c3_Err = authShell(p, "Konto anlegen").Render(templ.WithChildren(ctx, templ_7745c5c3_Var4), templ_7745c5c3_Buffer) templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var7), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
+22 -17
View File
@@ -1,5 +1,8 @@
package web package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// Me is the signed-in user as the console templates see it.
type Me struct { type Me struct {
Email string Email string
DisplayName string DisplayName string
@@ -9,6 +12,7 @@ type Me struct {
TOTPMissing bool TOTPMissing bool
} }
// Org is one entry of the organization switcher.
type Org struct { type Org struct {
ID string ID string
Name string Name string
@@ -31,16 +35,17 @@ templ consoleShell(p Page, me Me) {
<span class="text-muted">{ me.Orgs[0].Name }</span> <span class="text-muted">{ me.Orgs[0].Name }</span>
} }
<nav class="ml-auto flex items-center gap-5"> <nav class="ml-auto flex items-center gap-5">
<a href="/settings/security" class="text-muted hover:text-ink">Sicherheit</a> <a href="/settings/security" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.security") }</a>
<button data-logout class="text-muted hover:text-ink">Abmelden</button> <button data-logout class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.logout") }</button>
@languageSwitch(p.Languages)
</nav> </nav>
</div> </div>
</header> </header>
if me.TOTPMissing { if me.TOTPMissing {
<div class="border-b border-degraded/40 bg-degraded/10"> <div class="border-b border-degraded/40 bg-degraded/10">
<p class="mx-auto max-w-5xl px-6 py-2 text-sm"> <p class="mx-auto max-w-5xl px-6 py-2 text-sm">
Deine Organisation verlangt Zwei-Faktor-Anmeldung. { i18n.T(ctx, "console.totp_missing") }
<a href="/settings/security" class="underline underline-offset-2">Jetzt einrichten</a> <a href="/settings/security" class="underline underline-offset-2">{ i18n.T(ctx, "console.totp_missing_action") }</a>
</p> </p>
</div> </div>
} }
@@ -52,35 +57,35 @@ templ consoleShell(p Page, me Me) {
templ Dashboard(p Page, me Me) { templ Dashboard(p Page, me Me) {
@consoleShell(p, me) { @consoleShell(p, me) {
<h1 class="text-lg font-semibold">Monitore</h1> <h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
<p class="mt-2 text-sm text-muted">Noch keine Monitore angelegt.</p> <p class="mt-2 text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
} }
} }
templ Security(p Page, me Me) { templ Security(p Page, me Me) {
@consoleShell(p, me) { @consoleShell(p, me) {
<h1 class="mb-8 text-lg font-semibold">Sicherheit</h1> <h1 class="mb-8 text-lg font-semibold">{ i18n.T(ctx, "security.title") }</h1>
<section class="max-w-md"> <section class="max-w-md">
<h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">Zwei-Faktor (TOTP)</h2> <h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "security.totp.heading") }</h2>
if me.TOTP { if me.TOTP {
<p class="mb-6 text-sm"><span class="text-up">●</span> aktiv</p> <p class="mb-6 text-sm"><span class="text-up">●</span> { i18n.T(ctx, "security.totp.active") }</p>
<form data-api="/me/totp/disable" data-next="/settings/security"> <form data-api="/me/totp/disable" data-next="/settings/security">
@formError() @formError()
@field("Passwort", "password", "password", "current-password", true) @field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
@field("Aktueller Code", "code", "text", "one-time-code", true) @field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true)
@submit("Deaktivieren") @submit(i18n.T(ctx, "security.totp.disable"))
</form> </form>
} else { } else {
<p class="mb-6 text-sm"><span class="text-unknown">●</span> nicht eingerichtet</p> <p class="mb-6 text-sm"><span class="text-unknown">●</span> { i18n.T(ctx, "security.totp.inactive") }</p>
<div data-totp-setup> <div data-totp-setup>
<button data-totp-start class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">Einrichten</button> <button data-totp-start class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "security.totp.start") }</button>
<div data-totp-panel hidden> <div data-totp-panel hidden>
<img data-totp-qr alt="QR-Code für die Authenticator-App" class="mb-3 h-48 w-48 border border-rule bg-white p-2"/> <img data-totp-qr alt={ i18n.T(ctx, "security.totp.qr_alt") } class="mb-3 h-48 w-48 border border-rule bg-white p-2"/>
<p class="mb-6 break-all font-mono text-xs text-muted" data-totp-secret></p> <p class="mb-6 break-all font-mono text-xs text-muted" data-totp-secret></p>
<form data-api="/me/totp/enable" data-next="/settings/security"> <form data-api="/me/totp/enable" data-next="/settings/security">
@formError() @formError()
@field("Code aus der App", "code", "text", "one-time-code", true) @field(i18n.T(ctx, "security.totp.app_code"), "code", "text", "one-time-code", true)
@submit("Bestätigen") @submit(i18n.T(ctx, "security.totp.confirm"))
</form> </form>
</div> </div>
</div> </div>
+191 -23
View File
@@ -9,6 +9,9 @@ package web
import "github.com/a-h/templ" import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime" import templruntime "github.com/a-h/templ/runtime"
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// Me is the signed-in user as the console templates see it.
type Me struct { type Me struct {
Email string Email string
DisplayName string DisplayName string
@@ -18,6 +21,7 @@ type Me struct {
TOTPMissing bool TOTPMissing bool
} }
// Org is one entry of the organization switcher.
type Org struct { type Org struct {
ID string ID string
Name string Name string
@@ -72,7 +76,7 @@ func consoleShell(p Page, me Me) templ.Component {
var templ_7745c5c3_Var3 string var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(o.ID).Resolve(ctx) templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(o.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 27, Col: 27} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 31, Col: 27}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -95,7 +99,7 @@ func consoleShell(p Page, me Me) templ.Component {
var templ_7745c5c3_Var4 string var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(o.Name) templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(o.Name)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 27, Col: 73} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 31, Col: 73}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -118,7 +122,7 @@ func consoleShell(p Page, me Me) templ.Component {
var templ_7745c5c3_Var5 string var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(me.Orgs[0].Name) templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(me.Orgs[0].Name)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 31, Col: 47} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 35, Col: 47}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -129,17 +133,77 @@ func consoleShell(p Page, me Me) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<nav class=\"ml-auto flex items-center gap-5\"><a href=\"/settings/security\" class=\"text-muted hover:text-ink\">Sicherheit</a> <button data-logout class=\"text-muted hover:text-ink\">Abmelden</button></nav></div></header>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<nav class=\"ml-auto flex items-center gap-5\"><a href=\"/settings/security\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.security"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 38, Col: 105}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</a> <button data-logout class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.logout"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 39, Col: 94}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</button>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = languageSwitch(p.Languages).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</nav></div></header>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if me.TOTPMissing { if me.TOTPMissing {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<div class=\"border-b border-degraded/40 bg-degraded/10\"><p class=\"mx-auto max-w-5xl px-6 py-2 text-sm\">Deine Organisation verlangt Zwei-Faktor-Anmeldung. <a href=\"/settings/security\" class=\"underline underline-offset-2\">Jetzt einrichten</a></p></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<div class=\"border-b border-degraded/40 bg-degraded/10\"><p class=\"mx-auto max-w-5xl px-6 py-2 text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.totp_missing"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 47, Col: 42}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, " <a href=\"/settings/security\" class=\"underline underline-offset-2\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.totp_missing_action"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 48, Col: 115}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</a></p></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " <main class=\"mx-auto max-w-5xl px-6 py-10\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, " <main class=\"mx-auto max-w-5xl px-6 py-10\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -147,7 +211,7 @@ func consoleShell(p Page, me Me) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</main>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</main>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -178,7 +242,7 @@ func Dashboard(p Page, me Me) templ.Component {
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var7 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_Var11 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
@@ -190,13 +254,39 @@ func Dashboard(p Page, me Me) templ.Component {
}() }()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<h1 class=\"text-lg font-semibold\">Monitore</h1><p class=\"mt-2 text-sm text-muted\">Noch keine Monitore angelegt.</p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<h1 class=\"text-lg font-semibold\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 60, Col: 75}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</h1><p class=\"mt-2 text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.empty"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 61, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
return nil return nil
}) })
templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var7), templ_7745c5c3_Buffer) templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -221,7 +311,7 @@ func Security(p Page, me Me) templ.Component {
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var9 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_Var15 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
@@ -233,12 +323,51 @@ func Security(p Page, me Me) templ.Component {
}() }()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<h1 class=\"mb-8 text-lg font-semibold\">Sicherheit</h1><section class=\"max-w-md\"><h2 class=\"mb-1 text-xs font-medium uppercase tracking-wider text-muted\">Zwei-Faktor (TOTP)</h2>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<h1 class=\"mb-8 text-lg font-semibold\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 67, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</h1><section class=\"max-w-md\"><h2 class=\"mb-1 text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.heading"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 69, Col: 114}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</h2>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if me.TOTP { if me.TOTP {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<p class=\"mb-6 text-sm\"><span class=\"text-up\">●</span> aktiv</p><form data-api=\"/me/totp/disable\" data-next=\"/settings/security\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<p class=\"mb-6 text-sm\"><span class=\"text-up\">●</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var18 string
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.active"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 71, Col: 98}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</p><form data-api=\"/me/totp/disable\" data-next=\"/settings/security\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -246,24 +375,63 @@ func Security(p Page, me Me) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Passwort", "password", "password", "current-password", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Aktueller Code", "code", "text", "one-time-code", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = submit("Deaktivieren").Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = submit(i18n.T(ctx, "security.totp.disable")).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</form>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</form>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} else { } else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<p class=\"mb-6 text-sm\"><span class=\"text-unknown\">●</span> nicht eingerichtet</p><div data-totp-setup><button data-totp-start class=\"border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">Einrichten</button><div data-totp-panel hidden><img data-totp-qr alt=\"QR-Code für die Authenticator-App\" class=\"mb-3 h-48 w-48 border border-rule bg-white p-2\"><p class=\"mb-6 break-all font-mono text-xs text-muted\" data-totp-secret></p><form data-api=\"/me/totp/enable\" data-next=\"/settings/security\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<p class=\"mb-6 text-sm\"><span class=\"text-unknown\">●</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var19 string
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.inactive"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 79, Col: 105}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</p><div data-totp-setup><button data-totp-start class=\"border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var20 string
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.start"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 81, Col: 141}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</button><div data-totp-panel hidden><img data-totp-qr alt=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var21 string
templ_7745c5c3_Var21, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "security.totp.qr_alt")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 83, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "\" class=\"mb-3 h-48 w-48 border border-rule bg-white p-2\"><p class=\"mb-6 break-all font-mono text-xs text-muted\" data-totp-secret></p><form data-api=\"/me/totp/enable\" data-next=\"/settings/security\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -271,26 +439,26 @@ func Security(p Page, me Me) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = field("Code aus der App", "code", "text", "one-time-code", true).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = field(i18n.T(ctx, "security.totp.app_code"), "code", "text", "one-time-code", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = submit("Bestätigen").Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = submit(i18n.T(ctx, "security.totp.confirm")).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</form></div></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</form></div></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</section>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "</section>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
return nil return nil
}) })
templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var9), templ_7745c5c3_Buffer) templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var15), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
+26 -7
View File
@@ -1,35 +1,54 @@
package web package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// Page carries what every rendered page needs besides its own content.
type Page struct { type Page struct {
Title string TitleID string
CSRF string CSRF string
Languages []string
} }
templ Layout(p Page) { templ Layout(p Page) {
<!DOCTYPE html> <!DOCTYPE html>
<html lang="de"> <html lang={ i18n.Lang(ctx) }>
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="viewport" content="width=device-width, initial-scale=1"/>
if p.CSRF != "" { if p.CSRF != "" {
<meta name="csrf-token" content={ p.CSRF }/> <meta name="csrf-token" content={ p.CSRF }/>
} }
<title>{ p.Title } · uptimesebi</title> <title>{ i18n.T(ctx, p.TitleID) } · uptimesebi</title>
<link rel="stylesheet" href="/static/dist/app.css"/> <link rel="stylesheet" href="/static/dist/app.css"/>
<script src="/static/dist/axios.min.js" defer></script> <script src="/static/dist/axios.min.js" defer></script>
<script src="/static/dist/app.js" defer></script> <script src="/static/dist/app.js" defer></script>
</head> </head>
<body class="min-h-screen"> <body class="min-h-screen" data-msg-network={ i18n.T(ctx, "app.network_error") }>
{ children... } { children... }
</body> </body>
</html> </html>
} }
templ authShell(p Page, heading string) { templ languageSwitch(langs []string) {
<span class="flex gap-2 font-mono text-xs">
for _, l := range langs {
if l == i18n.Lang(ctx) {
<span class="text-ink" aria-current="true">{ l }</span>
} else {
<button type="button" data-locale={ l } class="text-muted hover:text-ink" title={ i18n.T(ctx, "lang."+l) }>{ l }</button>
}
}
</span>
}
templ authShell(p Page) {
@Layout(p) { @Layout(p) {
<main class="mx-auto mt-[12vh] w-full max-w-sm px-6"> <main class="mx-auto mt-[12vh] w-full max-w-sm px-6">
<p class="mb-10 font-mono text-xs tracking-wide text-muted">uptimesebi</p> <div class="mb-10 flex items-baseline justify-between">
<h1 class="mb-6 text-xl font-semibold">{ heading }</h1> <p class="font-mono text-xs tracking-wide text-muted">uptimesebi</p>
@languageSwitch(p.Languages)
</div>
<h1 class="mb-6 text-xl font-semibold">{ i18n.T(ctx, p.TitleID) }</h1>
{ children... } { children... }
</main> </main>
} }
+193 -61
View File
@@ -9,9 +9,13 @@ package web
import "github.com/a-h/templ" import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime" import templruntime "github.com/a-h/templ/runtime"
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// Page carries what every rendered page needs besides its own content.
type Page struct { type Page struct {
Title string TitleID string
CSRF string CSRF string
Languages []string
} }
func Layout(p Page) templ.Component { func Layout(p Page) templ.Component {
@@ -32,43 +36,69 @@ func Layout(p Page) templ.Component {
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"de\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if p.CSRF != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<meta name=\"csrf-token\" content=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var2 string var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(p.CSRF).Resolve(ctx) templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.Lang(ctx)).Resolve(ctx)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 15, Col: 44} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 14, Col: 28}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} if p.CSRF != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<title>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<meta name=\"csrf-token\" content=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var3 string var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(p.Title) templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(p.CSRF).Resolve(ctx)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 17, Col: 19} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 19, Col: 44}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " · uptimesebi</title><link rel=\"stylesheet\" href=\"/static/dist/app.css\"><script src=\"/static/dist/axios.min.js\" defer></script><script src=\"/static/dist/app.js\" defer></script></head><body class=\"min-h-screen\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<title>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 21, Col: 34}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " · uptimesebi</title><link rel=\"stylesheet\" href=\"/static/dist/app.css\"><script src=\"/static/dist/axios.min.js\" defer></script><script src=\"/static/dist/app.js\" defer></script></head><body class=\"min-h-screen\" data-msg-network=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "app.network_error")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 26, Col: 80}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -76,7 +106,7 @@ func Layout(p Page) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</body></html>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "</body></html>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -84,7 +114,7 @@ func Layout(p Page) templ.Component {
}) })
} }
func authShell(p Page, heading string) templ.Component { func languageSwitch(langs []string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -100,9 +130,103 @@ func authShell(p Page, heading string) templ.Component {
}() }()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var4 := templ.GetChildren(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var5 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<span class=\"flex gap-2 font-mono text-xs\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, l := range langs {
if l == i18n.Lang(ctx) {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<span class=\"text-ink\" aria-current=\"true\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(l)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 36, Col: 50}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<button type=\"button\" data-locale=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templruntime.NewAttributeExpression(l).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 38, Col: 41}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\" class=\"text-muted hover:text-ink\" title=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "lang."+l)).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 38, Col: 108}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(l)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 38, Col: 114}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</button>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
func authShell(p Page) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var11 := templ.GetChildren(ctx)
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var12 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
@@ -114,34 +238,42 @@ func authShell(p Page, heading string) templ.Component {
}() }()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<main class=\"mx-auto mt-[12vh] w-full max-w-sm px-6\"><p class=\"mb-10 font-mono text-xs tracking-wide text-muted\">uptimesebi</p><h1 class=\"mb-6 text-xl font-semibold\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<main class=\"mx-auto mt-[12vh] w-full max-w-sm px-6\"><div class=\"mb-10 flex items-baseline justify-between\"><p class=\"font-mono text-xs tracking-wide text-muted\">uptimesebi</p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var6 string templ_7745c5c3_Err = languageSwitch(p.Languages).Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(heading)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 32, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "</h1>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</div><h1 class=\"mb-6 text-xl font-semibold\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templ_7745c5c3_Var4.Render(ctx, templ_7745c5c3_Buffer) var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 51, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</main>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</h1>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ_7745c5c3_Var11.Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</main>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
return nil return nil
}) })
templ_7745c5c3_Err = Layout(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) templ_7745c5c3_Err = Layout(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var12), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -166,69 +298,69 @@ func field(label, name, typ, autocomplete string, required bool) templ.Component
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<label class=\"mb-4 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<label class=\"mb-4 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var8 string var templ_7745c5c3_Var15 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(label) templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(label)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 40, Col: 90} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 59, Col: 90}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</span> <input class=\"w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink\" type=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</span> <input class=\"w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink\" type=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var9 string var templ_7745c5c3_Var16 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(typ).Resolve(ctx) templ_7745c5c3_Var16, templ_7745c5c3_Err = templruntime.NewAttributeExpression(typ).Resolve(ctx)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 43, Col: 13} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 62, Col: 13}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "\" name=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\" name=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var10 string var templ_7745c5c3_Var17 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx) templ_7745c5c3_Var17, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 44, Col: 14} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 63, Col: 14}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\" autocomplete=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "\" autocomplete=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var11 string var templ_7745c5c3_Var18 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templruntime.NewAttributeExpression(autocomplete).Resolve(ctx) templ_7745c5c3_Var18, templ_7745c5c3_Err = templruntime.NewAttributeExpression(autocomplete).Resolve(ctx)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 45, Col: 30} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 64, Col: 30}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if required { if required {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " required") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, " required")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "></label>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "></label>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -253,20 +385,20 @@ func submit(label string) templ.Component {
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<button type=\"submit\" class=\"mt-2 w-full bg-ink px-3 py-2 text-sm font-medium text-paper hover:opacity-90 disabled:opacity-50\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<button type=\"submit\" class=\"mt-2 w-full bg-ink px-3 py-2 text-sm font-medium text-paper hover:opacity-90 disabled:opacity-50\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var13 string var templ_7745c5c3_Var20 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(label) templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(label)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 53, Col: 9} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 72, Col: 9}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</button>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</button>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -291,7 +423,7 @@ func formError() templ.Component {
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<p data-error class=\"mb-4 hidden border-l-2 border-down pl-2 text-sm text-down\"></p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<p data-error class=\"mb-4 hidden border-l-2 border-down pl-2 text-sm text-down\"></p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }