| 1 | package docs |
| 2 | |
| 3 | import ( |
| 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/rastrillo/rastrillo" |
| 10 | ) |
| 11 | |
| 12 | // homeLinkPage is views/home_link.html's data: the Home account-connection |
| 13 | // screens, and the signed-out page (SignedOut set, everything else empty). |
| 14 | type homeLinkPage struct { |
| 15 | Frame Frame |
| 16 | Title, Body, Address, Action, ActionLabel, CancelLabel string |
| 17 | PostAction bool |
| 18 | SignedOut *chrome.SignInNotice |
| 19 | } |
| 20 | |
| 21 | func (rd *renderer) homeLink(w http.ResponseWriter, r *http.Request, state, address string, status int) { |
| 22 | page := homeLinkPage{Address: address} |
| 23 | key := "docs.home." |
| 24 | switch state { |
| 25 | case "start": |
| 26 | page.Action, page.PostAction = "/account/home", true |
| 27 | page.ActionLabel = rastrillo.T(r, key+"start_action") |
| 28 | case "confirm": |
| 29 | page.Action, page.PostAction = "/account/home/confirm", true |
| 30 | page.ActionLabel = rastrillo.T(r, key+"confirm_action") |
| 31 | case "unknown": |
| 32 | page.Action = "/signin/local" |
| 33 | page.ActionLabel = rastrillo.T(r, key+"local_action") |
| 34 | case "signedout": |
| 35 | // The signed-out page (spec §9.2), in the door's words, with Sign |
| 36 | // in going back through Home when it is configured. |
| 37 | notice := chrome.SignInNotice{Icon: brand.Path("docs"), App: "Docs", Sky: sky.For(r.Host)}.SignedOut("/signin") |
| 38 | page.SignedOut, page.Title = ¬ice, notice.Page() |
| 39 | case "success": |
| 40 | page.Action = "/" |
| 41 | page.ActionLabel = rastrillo.T(r, key+"documents_action") |
| 42 | default: |
| 43 | state = "failed" |
| 44 | page.Action = "/account/home" |
| 45 | page.ActionLabel = rastrillo.T(r, key+"menu_action") |
| 46 | } |
| 47 | if page.SignedOut == nil { |
| 48 | page.Title = rastrillo.T(r, key+state+"_title") |
| 49 | page.Body = rastrillo.T(r, key+state+"_body") |
| 50 | } |
| 51 | if state == "start" || state == "confirm" { |
| 52 | page.CancelLabel = rastrillo.T(r, key+"cancel_action") |
| 53 | } |
| 54 | if rd.frame != nil { |
| 55 | page.Frame = rd.frame(r, frameOptions{titleParts: []string{page.Title}, signinPage: state == "signedout"}) |
| 56 | } |
| 57 | w.Header().Set("Cache-Control", "no-store") |
| 58 | if err := rd.pageStatus(w, r, "home-link", page, status); err != nil { |
| 59 | http.Error(w, rastrillo.T(r, "docs.error.generic"), http.StatusInternalServerError) |
| 60 | } |
| 61 | } |
| 62 | |