| 1 | package connect |
| 2 | |
| 3 | import ( |
| 4 | "embed" |
| 5 | "net/http" |
| 6 | |
| 7 | "amadan.net/oficina/estilo.git/homeconnect" |
| 8 | "amadan.net/oficina/home/handoff" |
| 9 | ) |
| 10 | |
| 11 | func Templates() embed.FS { return homeconnect.Templates() } |
| 12 | |
| 13 | // PageData is a connect page's data: estilo's homeconnect.PageData, whose |
| 14 | // home-connect template draws it, plus ForgetAction for the signed-out page. |
| 15 | // It was an alias of homeconnect.PageData until the smart door (Home spec |
| 16 | // 2026-11-19-smart-door.md); the shared fields keep their names, so a |
| 17 | // template or an embedding struct reads it as before. |
| 18 | type PageData struct { |
| 19 | Title, Body, Address, Action, ActionLabel, CancelLabel string |
| 20 | PostAction bool |
| 21 | // ForgetAction is the signed-out page's second form, "Forget me on this |
| 22 | // device": a POST with no fields to the app's rastrillo auth Forget |
| 23 | // (RoutesConfig.ForgetPath), which forgets how this browser last signed |
| 24 | // in here, for a shared computer. "" draws none. Set by PageFor on the |
| 25 | // request Routes.SignedOut renders, never by Page. Draw it with estilo's |
| 26 | // estilo-signed-out: |
| 27 | // |
| 28 | // chrome.SignInNotice{…}.SignedOut(p.Action).Forgetting(p.ForgetAction, "") |
| 29 | // |
| 30 | // which supplies the label. It forgets this host only: each host keeps |
| 31 | // its own record, and id.oficina.works offers its own Forget. |
| 32 | ForgetAction string |
| 33 | } |
| 34 | |
| 35 | // PageFor is Page for the request being answered. On "Accounts connected" |
| 36 | // its way back is the page the link began from, where Page's is "/". On the |
| 37 | // signed-out page Routes.SignedOut renders, it carries ForgetAction. |
| 38 | func PageFor(r *http.Request, state, label string, translate ...func(string) string) PageData { |
| 39 | p := Page(state, label, translate...) |
| 40 | if back, ok := r.Context().Value(successReturnKey{}).(string); ok && state == "success" && handoff.SafePath(back) { |
| 41 | p.Action = back |
| 42 | } |
| 43 | if forget, ok := r.Context().Value(forgetKey{}).(string); ok && state == "signedout" && localPath(forget) { |
| 44 | p.ForgetAction = forget |
| 45 | } |
| 46 | return p |
| 47 | } |
| 48 | |
| 49 | func Page(state, label string, translate ...func(string) string) PageData { |
| 50 | t := func(k string) string { return English[k] } |
| 51 | if len(translate) > 0 && translate[0] != nil { |
| 52 | t = translate[0] |
| 53 | } |
| 54 | p := PageData{Address: label} |
| 55 | switch state { |
| 56 | case "start": |
| 57 | p.Action = "/account/home" |
| 58 | p.PostAction = true |
| 59 | p.ActionLabel = t("start_action") |
| 60 | case "confirm": |
| 61 | p.Action = "/account/home/confirm" |
| 62 | p.PostAction = true |
| 63 | p.ActionLabel = t("confirm_action") |
| 64 | case "unknown": |
| 65 | p.Action = SigninLocalPath |
| 66 | p.ActionLabel = t("local_action") |
| 67 | case "signedout": |
| 68 | p.Action = SigninPath |
| 69 | p.ActionLabel = t("signedout_action") |
| 70 | case "success": |
| 71 | p.Action = "/" |
| 72 | p.ActionLabel = t("documents_action") |
| 73 | default: |
| 74 | state = "failed" |
| 75 | p.Action = SigninLocalPath |
| 76 | p.ActionLabel = t("local_action") |
| 77 | } |
| 78 | p.Title = t(state + "_title") |
| 79 | p.Body = t(state + "_body") |
| 80 | if state == "start" || state == "confirm" { |
| 81 | p.CancelLabel = t("cancel_action") |
| 82 | } |
| 83 | return p |
| 84 | } |
| 85 | |
| 86 | // English is the copy the apps render for connecting an account. It |
| 87 | // never names the hub: the account is "your Oficina account" (Paul, |
| 88 | // 2026-09-23), worded as Docs' approved docs.home.* strings are. The |
| 89 | // signed-out state speaks the door's words (estilo chrome.English). |
| 90 | // |
| 91 | // The confirm step must not read as the start page reloaded (Paul, |
| 92 | // 2026-10-24): it has its own question for a title and says the Oficina |
| 93 | // half is already done. The assertion carries an opaque subject and no |
| 94 | // address, so the Oficina account cannot be named, only the local one. |
| 95 | // The unknown state says what signing in will do, because it now does it: |
| 96 | // local sign-in resumes the link (localLinkNavigation.Complete). |
| 97 | // |
| 98 | // The choose_* strings are the member choice page (Home spec |
| 99 | // 2026-11-14-oficina-id-native.md §8), which Page does not draw: its two |
| 100 | // buttons carry ChoiceFor's token, so the app renders it with its own |
| 101 | // template from ChoiceFor and these labels. |
| 102 | var English = map[string]string{ |
| 103 | "signedout_title": "You’re signed out", "signedout_body": "You can sign in again with your Oficina account.", "signedout_action": "Sign in", |
| 104 | "start_title": "Connect your Oficina account", "start_body": "Use your Oficina account to sign in to this account. Your content and sharing settings stay as they are.", "start_action": "Connect", "cancel_action": "Back", |
| 105 | "confirm_title": "Connect these two accounts?", "confirm_body": "Your Oficina account is confirmed. Connect it to the account below, and you can sign in to that account with Oficina from now on.", "confirm_action": "Connect accounts", |
| 106 | "unknown_title": "Oficina account not connected", "unknown_body": "Sign in to your existing account once to connect it to your Oficina account.", "local_action": "Sign in to your existing account", |
| 107 | "choose_title": "Welcome to the team", "choose_body": "Do you already have an account here that signs in with email? Connect it, and your Oficina ID will open it from now on. If you’re new here, continue with Oficina ID.", "choose_connect_action": "Connect my existing account", "choose_new_action": "I’m new here — continue with Oficina ID", |
| 108 | "failed_title": "Could not connect accounts", "failed_body": "Return to the app and start again.", "success_title": "Accounts connected", "success_body": "You can now use your Oficina account to sign in to this account.", "documents_action": "Back to the app", "menu_action": "Connect your Oficina account", |
| 109 | } |
| 110 | |