oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1package docs
2
3import (
4 "net/http"
5
6 "amadan.net/oficina/estilo.git/brand"
7 "amadan.net/oficina/estilo.git/chrome"
8 "amadan.net/oficina/estilo.git/sky"
9 "amadan.net/oficina/home/connect"
10 "amadan.net/rastrillo/rastrillo"
11)
12
13// homeLinkPage is views/home_link.html's data: the Home account-connection
14// screens, and the signed-out page (SignedOut set, everything else empty).
15type homeLinkPage struct {
16 Frame Frame
17 Title, Body, Address, Action, ActionLabel, CancelLabel string
18 PostAction bool
19 SignedOut *chrome.SignInNotice
20 // Choice is the member choice page's two buttons (connect's
21 // ChoiceFor): both POST Action with choice and the form token.
22 Choice *homeChoice
23}
24
25type homeChoice struct {
26 Action, Token, ConnectLabel, NewLabel string
27}
28
29func (rd *renderer) homeLink(w http.ResponseWriter, r *http.Request, state, address string, status int) {
30 rd.homeLinkBack(w, r, state, address, "", status)
31}
32
33// homeLinkBack is homeLink with the success page's way back: the page the
34// link began from, already validated, or "" for the list.
35func (rd *renderer) homeLinkBack(w http.ResponseWriter, r *http.Request, state, address, back string, status int) {
36 page := homeLinkPage{Address: address}
37 key := "docs.home."
38 switch state {
39 case "start":
40 page.Action, page.PostAction = "/account/home", true
41 page.ActionLabel = rastrillo.T(r, key+"start_action")
42 case "confirm":
43 page.Action, page.PostAction = "/account/home/confirm", true
44 page.ActionLabel = rastrillo.T(r, key+"confirm_action")
45 case "unknown":
46 page.Action = "/signin/local"
47 page.ActionLabel = rastrillo.T(r, key+"local_action")
48 case "signedout":
49 // The signed-out page (spec §9.2), in the door's words: Sign in,
50 // then the quiet "Forget me on this device" (the smart-door spec's
51 // "Signed out"), a POST to rastrillo auth's Forget. With Home
52 // configured the page is connect's SignedOut, which carries that
53 // path (RoutesConfig.ForgetPath) for PageFor, and the form also
54 // asks Docs to go on to Oficina ID's own Forget once this one has
55 // answered (auth.go's forget). Standalone, it is Docs' own path.
56 p := connect.PageFor(r, "signedout", "")
57 forget, chain := p.ForgetAction, []chrome.Hidden{{Name: "chain", Value: oficinaChain}}
58 if forget == "" {
59 forget, chain = signinForgetPath, nil
60 }
61 notice := chrome.SignInNotice{Icon: brand.Path("docs"), App: "Docs", Sky: sky.For(r.Host)}.
62 SignedOut(p.Action).Forgetting(forget, "", chain...)
63 page.SignedOut, page.Title = &notice, notice.Page()
64 case "choose":
65 // A roster member with no account here yet (Home spec
66 // 2026-11-14-oficina-id-native.md §8): connect an existing
67 // email account, or continue with Oficina ID as someone new.
68 form, ok := connect.ChoiceFor(r)
69 if !ok {
70 state, status = "failed", http.StatusForbidden
71 page.Action = "/account/home"
72 page.ActionLabel = rastrillo.T(r, key+"menu_action")
73 break
74 }
75 page.Choice = &homeChoice{Action: form.Action, Token: form.Token, ConnectLabel: rastrillo.T(r, key+"choose_connect_action"), NewLabel: rastrillo.T(r, key+"choose_new_action")}
76 case "success":
77 page.Action = "/"
78 if back != "" {
79 page.Action = back
80 }
81 page.ActionLabel = rastrillo.T(r, key+"documents_action")
82 default:
83 state = "failed"
84 page.Action = "/account/home"
85 page.ActionLabel = rastrillo.T(r, key+"menu_action")
86 }
87 if page.SignedOut == nil {
88 page.Title = rastrillo.T(r, key+state+"_title")
89 page.Body = rastrillo.T(r, key+state+"_body")
90 }
91 if state == "start" || state == "confirm" {
92 page.CancelLabel = rastrillo.T(r, key+"cancel_action")
93 }
94 if rd.frame != nil {
95 page.Frame = rd.frame(r, frameOptions{titleParts: []string{page.Title}, signinPage: state == "signedout"})
96 }
97 w.Header().Set("Cache-Control", "no-store")
98 if err := rd.pageStatus(w, r, "home-link", page, status); err != nil {
99 http.Error(w, rastrillo.T(r, "docs.error.generic"), http.StatusInternalServerError)
100 }
101}
102