diff --git a/cmd/api/main.go b/cmd/api/main.go
index 092d55f..d94334f 100644
--- a/cmd/api/main.go
+++ b/cmd/api/main.go
@@ -8,8 +8,8 @@ import (
"time"
"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/i18n"
"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/sealed"
@@ -54,15 +54,16 @@ func run(log *slog.Logger, args []string) error {
}
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())
r := platform.NewRouter(log)
health.Register(r)
r.StaticFS("/static", web.Static())
-
- app := r.Group("/", srv.Sessions().Load(), auth.CSRF())
- srv.Register(app)
- srv.RegisterPages(app)
+ srv.Mount(r)
return platform.Serve(ctx, log, platform.NewHTTPServer(cfg.Listen, r), health, 5*time.Second, cfg.ShutdownTimeout)
}
diff --git a/internal/api/auth.go b/internal/api/auth.go
index 71472ea..f650cd4 100644
--- a/internal/api/auth.go
+++ b/internal/api/auth.go
@@ -16,6 +16,7 @@ import (
"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/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
)
@@ -46,12 +47,12 @@ func (s *Server) signup(c *gin.Context) {
internalError(c, err)
return
} else if !allowed {
- fail(c, http.StatusForbidden, "signup_closed", "Registrierung ist deaktiviert.")
+ fail(c, http.StatusForbidden, "signup_closed")
return
}
hash, err := auth.HashPassword(req.Password)
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
} else if err != nil {
internalError(c, err)
@@ -66,6 +67,7 @@ func (s *Server) signup(c *gin.Context) {
Email: normalizeEmail(req.Email),
DisplayName: strings.TrimSpace(req.DisplayName),
PasswordHash: &hash,
+ Locale: ptr(i18n.Lang(ctx)),
})
if err != nil {
return err
@@ -77,19 +79,19 @@ func (s *Server) signup(c *gin.Context) {
})
switch {
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
case isUniqueViolation(err, "orgs_slug_key"):
- fail(c, http.StatusConflict, "slug_taken", "Dieser Kurzname ist bereits vergeben.")
+ fail(c, http.StatusConflict, "slug_taken")
return
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
case err != nil:
internalError(c, err)
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) {
@@ -153,7 +155,7 @@ func (s *Server) login(c *gin.Context) {
}
if user.TotpSecret != nil {
- token := randomToken()
+ token := auth.RandomToken()
if err := s.rdb.Set(ctx, mfaKey(token), user.ID.String(), mfaTTL).Err(); err != nil {
internalError(c, err)
return
@@ -177,7 +179,7 @@ func (s *Server) loginTOTP(c *gin.Context) {
ctx := c.Request.Context()
token, _ := c.Cookie(mfaCookie)
if token == "" {
- fail(c, http.StatusUnauthorized, "mfa_expired", "Anmeldung abgelaufen, bitte erneut anmelden.")
+ fail(c, http.StatusUnauthorized, "mfa_expired")
return
}
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()
if err != nil {
- fail(c, http.StatusUnauthorized, "mfa_expired", "Anmeldung abgelaufen, bitte erneut anmelden.")
+ fail(c, http.StatusUnauthorized, "mfa_expired")
return
}
userID, err := uuid.Parse(raw)
@@ -199,7 +201,7 @@ func (s *Server) loginTOTP(c *gin.Context) {
return
}
if !ok {
- fail(c, http.StatusUnauthorized, "invalid_code", "Code ungültig.")
+ fail(c, http.StatusUnauthorized, "invalid_code")
return
}
_ = 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) {
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 {
var err error
+ if user, err = q.GetUser(ctx, userID); err != nil {
+ return err
+ }
orgs, err = q.ListUserOrgs(ctx, userID)
return err
})
@@ -223,14 +231,14 @@ func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID) {
if len(orgs) > 0 {
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 {
_ = 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 {
internalError(c, err)
return
@@ -271,7 +279,7 @@ func (s *Server) limit(c *gin.Context, key string, n int, window time.Duration)
}
if !ok {
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 true
@@ -285,7 +293,7 @@ func mfaKey(token string) string {
func normalizeEmail(e string) string { return strings.ToLower(strings.TrimSpace(e)) }
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 {
diff --git a/internal/api/me.go b/internal/api/me.go
index b7b60f7..d60e2b6 100644
--- a/internal/api/me.go
+++ b/internal/api/me.go
@@ -96,7 +96,7 @@ func (s *Server) switchOrg(c *gin.Context) {
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() }
@@ -109,7 +109,7 @@ func (s *Server) totpSetup(c *gin.Context) {
return
}
if me.TOTP {
- fail(c, http.StatusConflict, "totp_already_enabled", "TOTP ist bereits aktiv.")
+ fail(c, http.StatusConflict, "totp_already_enabled")
return
}
key, err := auth.NewTOTPKey(me.Email)
@@ -138,7 +138,7 @@ func (s *Server) totpEnable(c *gin.Context) {
sess := auth.Current(c)
secret, err := s.rdb.Get(ctx, totpSetupKey(sess.UserID)).Result()
if err != nil {
- fail(c, http.StatusConflict, "totp_setup_expired", "Einrichtung abgelaufen, bitte neu starten.")
+ fail(c, http.StatusConflict, "totp_setup_expired")
return
}
if !s.limit(c, "totp_enable:"+sess.UserID.String(), 10, totpSetupTTL) {
@@ -150,7 +150,7 @@ func (s *Server) totpEnable(c *gin.Context) {
return
}
if !ok {
- fail(c, http.StatusUnprocessableEntity, "invalid_code", "Code ungültig.")
+ fail(c, http.StatusUnprocessableEntity, "invalid_code")
return
}
sealedSecret := s.keys.Seal([]byte(secret), sess.UserID[:])
@@ -187,7 +187,7 @@ func (s *Server) totpDisable(c *gin.Context) {
}
for _, o := range me.Orgs {
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
}
}
@@ -202,7 +202,7 @@ func (s *Server) totpDisable(c *gin.Context) {
return
}
if user.PasswordHash == nil {
- fail(c, http.StatusConflict, "no_password", "Konto ohne Passwort.")
+ fail(c, http.StatusConflict, "no_password")
return
}
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)
return
} else if !ok {
- fail(c, http.StatusUnauthorized, "invalid_code", "Code ungültig.")
+ fail(c, http.StatusUnauthorized, "invalid_code")
return
}
err = s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error {
diff --git a/internal/api/pages.go b/internal/api/pages.go
index cc3a283..2d208cd 100644
--- a/internal/api/pages.go
+++ b/internal/api/pages.go
@@ -10,15 +10,15 @@ import (
"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("/signup", s.signupPage)
- r.GET("/", s.page("Übersicht", web.Dashboard))
- r.GET("/settings/security", s.page("Sicherheit", web.Security))
+ r.GET("/", s.page("console.monitors.title", web.Dashboard))
+ r.GET("/settings/security", s.page("security.title", web.Security))
}
-func pageFor(c *gin.Context, title string) web.Page {
- p := web.Page{Title: title}
+func (s *Server) pageFor(c *gin.Context, titleID string) web.Page {
+ p := web.Page{TitleID: titleID, Languages: s.catalog.Supported()}
if sess := auth.Current(c); sess != nil {
p.CSRF = sess.CSRF
}
@@ -35,7 +35,7 @@ func (s *Server) loginPage(c *gin.Context) {
internalError(c, err)
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) {
@@ -48,10 +48,10 @@ func (s *Server) signupPage(c *gin.Context) {
c.Redirect(http.StatusSeeOther, "/login")
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) {
sess := auth.Current(c)
if sess == nil {
@@ -63,7 +63,7 @@ func (s *Server) page(title string, view func(web.Page, web.Me) templ.Component)
internalError(c, err)
return
}
- web.Render(c, http.StatusOK, view(pageFor(c, title), toWebMe(me)))
+ web.Render(c, http.StatusOK, view(s.pageFor(c, titleID), toWebMe(me)))
}
}
diff --git a/internal/api/server.go b/internal/api/server.go
index 7d99408..56d6948 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -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
import (
@@ -11,40 +13,58 @@ import (
"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/i18n"
"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"
)
+const localeCookie = "lang"
+
+// Server holds the dependencies shared by all handlers.
type Server struct {
cfg config.API
log *slog.Logger
db *tenant.DB
rdb redis.UniversalClient
keys *sealed.Keyring
+ catalog *i18n.Catalog
sessions *auth.Sessions
limiter *auth.Limiter
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{
cfg: cfg,
- log: log,
- db: db,
- rdb: rdb,
- keys: keys,
- sessions: auth.NewSessions(rdb, cfg.SessionIdle, cfg.SessionAbsolute),
- limiter: auth.NewLimiter(rdb),
- totp: auth.NewTOTPVerifier(rdb),
+ log: d.Log,
+ db: d.DB,
+ rdb: d.Redis,
+ keys: d.Keys,
+ catalog: d.Catalog,
+ sessions: auth.NewSessions(d.Redis, cfg.SessionIdle, cfg.SessionAbsolute),
+ 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
-// Sessions().Load() and auth.CSRF() on the engine.
-func (s *Server) Register(r gin.IRouter) {
- v1 := r.Group("/api/v1")
+ v1 := g.Group("/api/v1")
+ v1.POST("/locale", s.setLocale)
a := v1.Group("/auth")
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/enable", s.totpEnable)
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 {
@@ -66,29 +135,35 @@ type apiError struct {
Fields map[string]string `json:"fields,omitempty"`
}
-func fail(c *gin.Context, status int, code, msg string) {
- c.AbortWithStatusJSON(status, apiError{Error: code, Message: msg})
+// fail aborts with a machine-readable code and a message translated from
+// the catalog entry "error. Noch kein Konto? Registrieren
+ { i18n.T(ctx, "auth.login.no_account") }
+ { i18n.T(ctx, "auth.login.to_signup") }
+ { i18n.T(ctx, "auth.signup.to_login") } Code aus der Authenticator-App eingeben. ")
if templ_7745c5c3_Err != nil {
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 {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "". 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) {
_ = 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 {
- if err := c.ShouldBindJSON(dst); err != nil {
- e := apiError{Error: "invalid_input", Message: "Eingaben prüfen."}
- var ve validator.ValidationErrors
- if errors.As(err, &ve) {
- e.Fields = map[string]string{}
- for _, f := range ve {
- e.Fields[f.Field()] = f.Tag()
- }
- }
- c.AbortWithStatusJSON(http.StatusBadRequest, e)
- return false
+ err := c.ShouldBindJSON(dst)
+ if err == nil {
+ return true
}
- return true
+ e := apiError{Error: "invalid_input", Message: i18n.T(c.Request.Context(), "error.invalid_input")}
+ var ve validator.ValidationErrors
+ if errors.As(err, &ve) {
+ e.Fields = map[string]string{}
+ for _, f := range ve {
+ e.Fields[f.Field()] = f.Tag()
+ }
+ }
+ c.AbortWithStatusJSON(http.StatusBadRequest, e)
+ return false
}
func setCookie(c *gin.Context, name, value string, maxAge int) {
@@ -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
+}
diff --git a/internal/web/assets/app.js b/internal/web/assets/app.js
index 3aa3820..9f8fb8b 100644
--- a/internal/web/assets/app.js
+++ b/internal/web/assets/app.js
@@ -8,7 +8,7 @@
window.api = api;
const message = (err) =>
- err.response?.data?.message ?? "Verbindung fehlgeschlagen.";
+ err.response?.data?.message ?? document.body.dataset.msgNetwork;
const showError = (form, text) => {
const el = form.querySelector("[data-error]");
@@ -50,6 +50,12 @@
});
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]")) {
await api.post("/auth/logout").catch(() => {});
location.assign("/login");
diff --git a/internal/web/auth.templ b/internal/web/auth.templ
index 912a2d7..c0f86d6 100644
--- a/internal/web/auth.templ
+++ b/internal/web/auth.templ
@@ -1,37 +1,45 @@
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) {
- @authShell(p, "Anmelden") {
+ @authShell(p) {
if signupAllowed {
-
Noch kein Konto? Registrieren
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "") + 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, " ") + 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, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } 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 { return templ_7745c5c3_Err } @@ -111,7 +155,7 @@ func Signup(p Page) templ.Component { } ctx = templ.InitializeContext(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_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -123,7 +167,7 @@ func Signup(p Page) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } 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 { return templ_7745c5c3_Err } diff --git a/internal/web/console.templ b/internal/web/console.templ index 5645c7b..4a7a5f0 100644 --- a/internal/web/console.templ +++ b/internal/web/console.templ @@ -1,5 +1,8 @@ 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 { Email string DisplayName string @@ -9,6 +12,7 @@ type Me struct { TOTPMissing bool } +// Org is one entry of the organization switcher. type Org struct { ID string Name string @@ -31,16 +35,17 @@ templ consoleShell(p Page, me Me) { { me.Orgs[0].Name } } if me.TOTPMissing {- Deine Organisation verlangt Zwei-Faktor-Anmeldung. - Jetzt einrichten + { i18n.T(ctx, "console.totp_missing") } + { i18n.T(ctx, "console.totp_missing_action") }
Noch keine Monitore angelegt.
+{ i18n.T(ctx, "console.monitors.empty") }
} } templ Security(p Page, me Me) { @consoleShell(p, me) { -● aktiv
+● { i18n.T(ctx, "security.totp.active") }
} else { -● nicht eingerichtet
+● { i18n.T(ctx, "security.totp.inactive") }
Deine Organisation verlangt Zwei-Faktor-Anmeldung. Jetzt einrichten
") + 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, " ") + 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, "
Noch keine Monitore angelegt.
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "") + 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, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } 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 { return templ_7745c5c3_Err } @@ -221,7 +311,7 @@ func Security(p Page, me Me) templ.Component { } ctx = templ.InitializeContext(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_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -233,12 +323,51 @@ func Security(p Page, me Me) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "● aktiv
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "● nicht eingerichtet
uptimesebi
-uptimesebi
+ @languageSwitch(p.Languages) +uptimesebi
uptimesebi
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var6 string - 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)) + 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, 8, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "