Files
felhom-controller/controller/internal/web/known_login.go
T

42 lines
1.9 KiB
Go

package web
import (
"strings"
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
)
// ── Known default logins (v0.279.0, `09` §3 decision 45) ────────────────────────────────────────────
//
// "An app is never published with a login a stranger knows." Where the template's after_install replaces
// the default with a generated password, the default is gone once that command succeeded — the page must
// then NOT show it (it would send the household to a login that no longer works). Where it cannot (no
// after_install) or the command failed, the page and the install dialog say plainly what the default is and
// to change it at once. Pinned by internal/web/known_login_test.go.
// defaultLoginInEffect: the template has a default login and nothing has replaced it on this install.
// installed=false is the install dialog, before the install: a declared after_install WILL replace it.
func defaultLoginInEffect(meta *stacks.Metadata, cfg *stacks.AppConfig, installed bool) bool {
if meta == nil || strings.TrimSpace(meta.AppInfo.DefaultCreds) == "" {
return false
}
if meta.AfterInstall == nil {
return true
}
if !installed {
return false
}
// Installed with an after_install: in effect only when the command FAILED (absent = not run yet — the
// deploy-done hook runs it within minutes; the page does not warn about a default it is replacing).
return cfg != nil && cfg.AfterInstall != nil && !cfg.AfterInstall.OK
}
// knownLoginLine is the sentence, in lang, or "" when no default login is in effect.
func (s *Server) knownLoginLine(lang string, meta *stacks.Metadata, cfg *stacks.AppConfig, installed bool) string {
if !defaultLoginInEffect(meta, cfg, installed) {
return ""
}
creds := strings.ReplaceAll(meta.AppInfo.DefaultCreds, "DOMAIN", s.cfg.Customer.Domain)
return s.msgLang(lang, "app_info.known_login", creds)
}