Reserved, setup-mode-only, loopback-only: the domain, the top admin, the authenticator (TOTP), mail/locale — then Finish persists and the dashboard becomes reachable. The wizard IS the bootstrap (D-026); the TOTP key is generated at startup so TOTP enrollment precedes Finish (SPEC-009 D-1).
95 lines
4.3 KiB
Go
95 lines
4.3 KiB
Go
package setup
|
|
|
|
import (
|
|
"html"
|
|
"net/http"
|
|
|
|
"git.lohmar.co.uk/cclohmar/NextMyDay/internal/core/web"
|
|
)
|
|
|
|
// renderHTML writes the wizard page inside the core shell (SPEC-009 §4). The
|
|
// door renders no dynamic HTML itself (SPEC-003 §4); the wizard is the hand-off
|
|
// target for the `setup` workflow.
|
|
//
|
|
// F-2: the bootstrap renders secrets and ceremony state — never cache it.
|
|
func renderHTML(w http.ResponseWriter, status int, page web.Page) error {
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
return web.Render(w, status, page)
|
|
}
|
|
|
|
// writeError writes a terse plain-text error.
|
|
func writeError(w http.ResponseWriter, status int, msg string) {
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.WriteHeader(status)
|
|
_, _ = w.Write([]byte(msg + "\n"))
|
|
}
|
|
|
|
// redirect sends the operator back to the wizard (post/redirect/get).
|
|
func redirect(w http.ResponseWriter, r *http.Request, path string) {
|
|
http.Redirect(w, r, path, http.StatusSeeOther)
|
|
}
|
|
|
|
// wizardPage renders the current step inside the shell. The wizard runs before
|
|
// any identity exists, so the page is a GUEST screen: no nav (SPEC-009 §4).
|
|
// Every form carries the signed pre-session CSRF token (A15).
|
|
func wizardPage(st step, token, domain string) web.Page {
|
|
c := html.EscapeString(token)
|
|
return web.Page{
|
|
Title: "MyDay setup",
|
|
Guest: true,
|
|
CSRF: token,
|
|
Content: web.Markup(`<h1>MyDay setup</h1>
|
|
<p>Bring this instance to life: the domain, the top admin, then mail and locale.</p>` +
|
|
stepBody(st, c, domain)),
|
|
}
|
|
}
|
|
|
|
// stepBody renders the section for one step.
|
|
func stepBody(st step, c, domain string) string {
|
|
switch st {
|
|
case stepDomain:
|
|
return `<section aria-label="domain"><h2>1. Domain</h2>` +
|
|
`<form method="post" action="/setup?do=setup&action=domain.save">` +
|
|
`<input type="hidden" name="csrf" value="` + c + `">` +
|
|
`<label>Base URL <input name="base_url" type="url" value="` +
|
|
html.EscapeString(domain) + `" placeholder="https://myday.example.com" required></label>` +
|
|
`<button type="submit">Continue</button></form></section>`
|
|
|
|
case stepAdmin:
|
|
return `<section aria-label="admin"><h2>2. The top admin</h2>` +
|
|
`<form method="post" action="/setup?do=setup&action=admin.create">` +
|
|
`<input type="hidden" name="csrf" value="` + c + `">` +
|
|
`<label>Display name <input name="display_name" autocomplete="name" required></label>` +
|
|
`<label>Email <input name="email" type="email" autocomplete="email" required></label>` +
|
|
`<button type="submit">Create the admin</button></form></section>`
|
|
|
|
case stepEnroll:
|
|
// Step 2 enrolls TOTP only (D-041): a passkey registered over loopback
|
|
// would bind RP ID 127.0.0.1 and be dead at the public domain. The
|
|
// admin adds a passkey at first login, via the nudge (SPEC-006 §8).
|
|
return `<section aria-label="enroll"><h2>2. Enroll the admin</h2>` +
|
|
`<p>Add an authenticator app. A passkey can be added later, at first sign-in.</p>` +
|
|
`<section aria-label="totp"><h3>Authenticator app</h3>` +
|
|
`<form method="post" action="/setup?do=setup&action=admin.totp.begin">` +
|
|
`<input type="hidden" name="csrf" value="` + c + `">` +
|
|
`<button type="submit" class="secondary">Set up authenticator</button></form>` +
|
|
`<form method="post" action="/setup?do=setup&action=admin.totp.verify">` +
|
|
`<input type="hidden" name="csrf" value="` + c + `">` +
|
|
`<label>Code <input name="code" inputmode="numeric" autocomplete="one-time-code"></label>` +
|
|
`<button type="submit">Verify code</button></form></section></section>`
|
|
|
|
default: // stepSettings
|
|
return `<section aria-label="settings"><h2>3. Mail · locale · timezone</h2>` +
|
|
`<form method="post" action="/setup?do=setup&action=finish">` +
|
|
`<input type="hidden" name="csrf" value="` + c + `">` +
|
|
`<label>SMTP host <input name="mail.host"></label>` +
|
|
`<label>SMTP port <input name="mail.port" inputmode="numeric"></label>` +
|
|
`<label>SMTP username <input name="mail.username"></label>` +
|
|
`<label>SMTP password <input name="mail.password" type="password"></label>` +
|
|
`<label>From address <input name="mail.from" type="email"></label>` +
|
|
`<label>Locale <input name="app.locale" value="en-GB"></label>` +
|
|
`<label>Timezone <input name="app.timezone" value="Europe/London"></label>` +
|
|
`<button type="submit">Finish setup</button></form></section>`
|
|
}
|
|
}
|