oficina / memoria Public

Clone
git clone https://amadan.net/oficina/memoria

Plain git — no account needed to clone.

Download

Download this file

1package memoria
2
3import (
4 "bytes"
5 "net/http"
6
7 "amadan.net/oficina/home/connect"
8)
9
10type homePage struct {
11 page
12 Home homeLinkView
13}
14
15// homeLinkView is the account-connection pages' data: connect's page, or
16// the member choice's two buttons when Choice is set. Both buttons POST
17// connect.ChoosePath with the form token, inside the app-wide CSRF check.
18type homeLinkView struct {
19 connect.PageData
20 Choice *homeChoice
21}
22
23type homeChoice struct {
24 Action, Token, ConnectLabel, NewLabel string
25}
26
27// renderHome is connect's Render: the account-link pages (link, confirm,
28// failed) and the member choice inside Memoria's layout, with the viewer's
29// own chrome, and the signed-out page, the door's own (renderSignedOut),
30// with "Forget me on this device".
31func (a *app) renderHome(w http.ResponseWriter, r *http.Request, state, label string, status int) {
32 if state == "signedout" {
33 a.renderSignedOut(w, r, status)
34 return
35 }
36 view := homeLinkView{PageData: connect.PageFor(r, state, label, func(k string) string { return homeCopy[k] })}
37 if state == "choose" {
38 // A roster member with no account here yet (Home spec
39 // 2026-11-14-oficina-id-native.md §8): connect an existing email
40 // account, or continue with Oficina ID as someone new. connect's
41 // Page knows no "choose", so the page is built here, in connect's
42 // own English, word for word as every other app draws it.
43 if form, ok := connect.ChoiceFor(r); ok {
44 view.Title, view.Body = connect.English["choose_title"], connect.English["choose_body"]
45 view.Choice = &homeChoice{Action: form.Action, Token: form.Token,
46 ConnectLabel: connect.English["choose_connect_action"], NewLabel: connect.English["choose_new_action"]}
47 } else {
48 // No live choice to offer: "failed", with the way on to
49 // connecting an account, as Docs, Sheets, Calendar and Calls do.
50 view.PageData = connect.PageFor(r, "failed", label, func(k string) string { return homeCopy[k] })
51 view.Action, view.ActionLabel = "/account/home", connect.English["menu_action"]
52 status = http.StatusForbidden
53 }
54 }
55 pg := a.pageFor(r, titled(view.Title))
56 var body bytes.Buffer
57 if err := pages["home"].ExecuteTemplate(&body, "layout", homePage{page: pg, Home: view}); err != nil {
58 plainError(w, http.StatusInternalServerError)
59 return
60 }
61 w.Header().Set("Content-Type", "text/html; charset=utf-8")
62 w.Header().Set("Cache-Control", "no-store")
63 w.WriteHeader(status)
64 _, _ = w.Write(body.Bytes())
65}
66
67// homeCopy is connect's account-connection copy (which already leaves
68// the hub unnamed — "your Oficina account" — and says Connect, Paul's
69// §13 answer 3), with only Memoria's own words on top. The same wording
70// Sheets and Slides use.
71var homeCopy = func() map[string]string {
72 out := make(map[string]string, len(connect.English))
73 for k, v := range connect.English {
74 out[k] = v
75 }
76 out["start_body"] = "Use your Oficina account to sign in to this account. What Memoria holds stays as it is."
77 out["documents_action"] = "Back to Memoria"
78 out["confirm_title"] = "Connect these two accounts?"
79 out["confirm_body"] = "Your Oficina account is confirmed. Connect it to the Memoria account below, and you can sign in to Memoria with Oficina from now on."
80 out["unknown_body"] = "Sign in to your Memoria account once to connect it to your Oficina account."
81 return out
82}()
83