Public: anyone can read this; the crew can change it.
Connections 1: one list of proven identities on the account, with the proven email and the Minecraft link moved into it #18168
Merged 4h 54m ago, live in production
scout/forge:scout/18160-connections-1-one-list-of-proven-identit → main 0 commits fork 4 threads · 4 unresolved
22 files
changed +761
−253
- docs/design/attention-budget.json
- docs/features/games.md
- docs/features/identities.md
- src/contract/openapi/routes/getApiV1Identities.ts
- src/contract/openapi/routes/index.ts
- src/contract/tags.ts
- src/core/proven_identities.ts
- src/core/verify.ts
- src/games/chat.ts
- src/generated/marks.ts
- src/http/api/user.ts
- src/http/lazy_lists.ts
- src/http/marks/api-v1-identities.json
- src/http/marks/settings.json
- src/http/settings_routes.ts
- src/tui/screens/profile.ts
- src/web/pages/account.ts
- src/web/pages/games.ts
- src/web/pages/proven_identities.ts
- src/web/pages/search.ts
- test/keymap-terminal.test.ts
- test/proven-identities.test.ts
docs/design/attention-budget.json +5 −5
| @@ -115,16 +115,16 @@ | ||
| 115 | 115 | }, |
| 116 | 116 | "settings": { |
| 117 | 117 | "390": { |
| 118 | "words": 157, | |
| 119 | "blocks": 32, | |
| 118 | "words": 163, | |
| 119 | "blocks": 35, | |
| 120 | 120 | "colours": 1 |
| 121 | 121 | }, |
| 122 | 122 | "1280": { |
| 123 | "words": 157, | |
| 124 | "blocks": 32, | |
| 123 | "words": 163, | |
| 124 | "blocks": 35, | |
| 125 | 125 | "colours": 1 |
| 126 | 126 | }, |
| 127 | "note": "146 words since #13308 (2026-11-15, Settings \u203a Connected agents): its side-nav entry added two words to the 144 main had; 147 since the forge dataset (Settings \u203a Dataset), one word; 148 since the Tables page (#6002), one word; 149 since Settings \u203a Infrastructure, one word: an admin looked for the cloud bill here and found no way to it; 153 since Settings › Who may do what (#18105), four words: every account sees what it may do and through which grant, so the row is on every account's nav. 155 since Settings › Proven emails (#18108), two words: its side-nav entry, so a person finds where their verified addresses are kept. 157 since Settings › Brought in (#18113), two words: its side-nav entry, so a person finds what they brought from a visitor and its undo." | |
| 127 | "note": "146 words since #13308 (2026-11-15, Settings \u203a Connected agents): its side-nav entry added two words to the 144 main had; 147 since the forge dataset (Settings \u203a Dataset), one word; 148 since the Tables page (#6002), one word; 149 since Settings \u203a Infrastructure, one word: an admin looked for the cloud bill here and found no way to it; 153 since Settings › Who may do what (#18105), four words: every account sees what it may do and through which grant, so the row is on every account's nav. 155 since Settings › Proven emails (#18108), two words: its side-nav entry, so a person finds where their verified addresses are kept. 157 since Settings › Brought in (#18113), two words: its side-nav entry, so a person finds what they brought from a visitor and its undo. 163 words and 35 blocks since Identities (#18160), six words and three blocks: the list of who you are is drawn for every account (the heading, the email, proven or not, and Remove), as its review asked, with no badge repeating the meta line." | |
| 128 | 128 | }, |
| 129 | 129 | "search": { |
| 130 | 130 | "390": { |
docs/features/games.md +1 −1
| @@ -86,7 +86,7 @@ Words beyond the few it knows are themes: "zombie survival with custom guns and | ||
| 86 | 86 | |
| 87 | 87 | ## From in the game |
| 88 | 88 | |
| 89 | A player can ask the forge from a server's chat (#17284). Link the name first: **Link your Minecraft name** under Minecraft on the account page (`/settings`), or `L` on the terminal's Games screen (`src/tui/screens/games.ts`), gives a one-time code (6 characters, 10 minutes, kept only as its hash) shown only to the person signed in. The block is there for everyone signed in once the forge has a game box, and neither door gives a code before that: a link gives no role. In chat on any server of the box, type `!forge link 4F7QXZ`; where the proxy has the plugin, type `/forge link 4F7QXZ`, then `/forge yes` and the six digits it shows. The link binds the account to the name and to the player's UUID as the server itself lists it (`list uuids`, the same answer People keeps as who is online), never to anything typed in chat; a Bedrock name (`.Name`) links the same way. A name the server does not list yet is told to stay on and try again, and the code stays good. Five wrong codes for a name lock it out for an hour. The account page lists the linked names with Unlink, and `/games/<box>` lists who is linked there to an operator of the box (anyone else sees their own links) and, to its owner, the last commands as they were typed (`/forge` or `!forge`, kept in `game_chat.door`; a question asked through the proxy before that column existed reads as `!forge`) and what came of each. The forge's words to a player in game are not in the service's console. | |
| 89 | A player can ask the forge from a server's chat (#17284). Link the name first: **Link your Minecraft name** under Identities on the account page (`/settings`), or `L` on the terminal's Games screen (`src/tui/screens/games.ts`), gives a one-time code (6 characters, 10 minutes, kept only as its hash) shown only to the person signed in. The block is there for everyone signed in once the forge has a game box, and neither door gives a code before that: a link gives no role. In chat on any server of the box, type `!forge link 4F7QXZ`; where the proxy has the plugin, type `/forge link 4F7QXZ`, then `/forge yes` and the six digits it shows. The link binds the account to the name and to the player's UUID as the server itself lists it (`list uuids`, the same answer People keeps as who is online), never to anything typed in chat; a Bedrock name (`.Name`) links the same way. A name the server does not list yet is told to stay on and try again, and the code stays good. Five wrong codes for a name lock it out for an hour. The account page lists the linked names under Identities, each proven (bound to a UUID) or unproven, with Unlink, and `/games/<box>` lists who is linked there to an operator of the box (anyone else sees their own links) and, to its owner, the last commands as they were typed (`/forge` or `!forge`, kept in `game_chat.door`; a question asked through the proxy before that column existed reads as `!forge`) and what came of each. The forge's words to a player in game are not in the service's console. | |
| 90 | 90 | |
| 91 | 91 | A linked name that holds any role on the server it types on, viewer too, can ask (`src/games/ask.ts`): `!forge who is on`, `why could I not join`, `what does survival need`, `is survival asleep`, `what is the address`. The forge answers from what it keeps, with no crew turn and no change (what a server needs may be looked up on Modrinth). Only those words and no more are a question. An answer names only servers the account has a role on, and the player's own refused joins there and nobody else's: a refusal by a server the account has no role on is answered as if it never was. "Why" repeats the server's own words for the refusal, as the proxy logged them, with network addresses (IPv4 and IPv6) taken out; nothing else in an answer is from a log. Questions count in the limits below. |
| 92 | 92 |
docs/features/identities.md added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | --- | |
| 2 | topic: Every setting, by topic | |
| 3 | row: Identities | |
| 4 | --- | |
| 5 | # Identities | |
| 6 | ||
| 7 | One list per account (#18160), `src/core/proven_identities.ts`. Each identity is **proven** or **unproven**, and only a proven one counts. | |
| 8 | ||
| 9 | - **Web:** the **Identities** block on `/settings` (`src/web/pages/proven_identities.ts`): your email, with *Send another link* while it is unproven and *Remove*; where the forge has a game box or you have a linked name, your Minecraft names with *Unlink* and *Link your Minecraft name*. | |
| 10 | - **Terminal:** **Your profile** (`src/tui/screens/profile.ts`) lists the same identities under *Identities*, one line each, for example `Email [email protected]: proven` or `Minecraft adacraft: proven on mc`. `e` sets the email, `r` removes it, `l` gives a Minecraft link code and `u` unlinks a name. | |
| 11 | - **API:** `GET /api/v1/identities` answers the same list: `kind`, `name`, `proven`, `since`, for a Minecraft name its `box` and `uuid`, and `line`, the sentence both doors print. | |
| 12 | ||
| 13 | ## The two kinds | |
| 14 | ||
| 15 | - **Email.** It is added when you set the address (the Email field on `/settings`, `e` on Your profile). It is proven by the one-time link mailed to it: only the link's hash is kept, it works once, and it expires after 24 hours. When you change the address, the new one is unproven again. *Remove* takes it off the list once you type the address back on its confirm page (`r` asks first too): the account keeps a stand-in address no mail reaches, and nothing waits on a proven email until you add one again. An agent's or organization's email counts as proven, as before. | |
| 16 | - **Minecraft.** It is added with a one-time code that you type in game (`!forge link <code>`, see [](games.md)). It is proven while it is bound to the UUID the server lists for the name. A name bound to no UUID shows as unproven: link it again. **Unlink** removes it. | |
| 17 | ||
| 18 | Every check on a proven email reads this list: who may make repositories, apps and runs, the mail sent as you, the bill address, and `emailVerified` in `GET /api/v1/user` and the MCP `profile` tool. The game chat finds an account by its Minecraft name the same way. |
src/contract/openapi/routes/getApiV1Identities.ts added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | import { bool, list, obj, orNull, str } from "../schema_kit.ts"; | |
| 2 | import type { Route } from "../shared.ts"; | |
| 3 | ||
| 4 | export const route: Route = { | |
| 5 | method: "get", | |
| 6 | path: "/api/v1/identities", | |
| 7 | summary: "Read who you are: your email and Minecraft names, each proven or unproven", | |
| 8 | detail: "The same list Settings › Identities and the terminal's Your profile show (#18160): the email first, then each linked Minecraft name with its box and UUID. `line` is the sentence both doors print. Remove the email with POST /settings/email/remove or `r` in the terminal; unlink a name with POST /settings/minecraft/unlink or `u`.", | |
| 9 | response: obj({ identities: list(obj({ kind: str, name: str, proven: bool, since: orNull(str), line: str })) }), | |
| 10 | auth: true, | |
| 11 | role: "member", | |
| 12 | refuses: [401], | |
| 13 | }; |
src/contract/openapi/routes/index.ts +1
| @@ -140,6 +140,7 @@ export { route as getApiV1Here } from "./getApiV1Here.ts"; | ||
| 140 | 140 | export { route as getApiV1HomeLanes } from "./getApiV1HomeLanes.ts"; |
| 141 | 141 | export { route as getApiV1HomeSlots } from "./getApiV1HomeSlots.ts"; |
| 142 | 142 | export { route as getApiV1HomeStrip } from "./getApiV1HomeStrip.ts"; |
| 143 | export { route as getApiV1Identities } from "./getApiV1Identities.ts"; | |
| 143 | 144 | export { route as getApiV1Keeper } from "./getApiV1Keeper.ts"; |
| 144 | 145 | export { route as getApiV1KeeperPulse } from "./getApiV1KeeperPulse.ts"; |
| 145 | 146 | export { route as getApiV1MailAws } from "./getApiV1MailAws.ts"; |
src/contract/tags.ts +1
src/core/proven_identities.ts added +153
| @@ -0,0 +1,153 @@ | ||
| 1 | /** | |
| 2 | * Who someone is, in one list (#18160): every identity an account has connected, each proven or | |
| 3 | * not. Its first two kinds are the account's email (proven by a one-time, hashed, expiring link: | |
| 4 | * `core/verify.ts` keeps the codes) and a Minecraft name (proven by a one-time code typed in game: | |
| 5 | * `games/chat.ts`). Every place that asks "is this email proven" or "which names are theirs" reads | |
| 6 | * this list, so there is no second answer. | |
| 7 | * | |
| 8 | * Not `core/connections.ts` (model backends) nor `core/identities.ts` (#18108: further emails a | |
| 9 | * person proves and opts into lookups with): this is the account's own email and Minecraft names. | |
| 10 | * Plain data in, plain data out; the codes and the network are the callers'. | |
| 11 | */ | |
| 12 | import type { Database } from "bun:sqlite"; | |
| 13 | ||
| 14 | export type IdentityKind = "email" | "minecraft"; | |
| 15 | ||
| 16 | export interface Identity { | |
| 17 | readonly kind: IdentityKind; | |
| 18 | /** The address, or the player name. */ | |
| 19 | readonly name: string; | |
| 20 | readonly proven: boolean; | |
| 21 | /** When it was proven (email) or linked (Minecraft); null while unproven. */ | |
| 22 | readonly since: string | null; | |
| 23 | /** Minecraft: the box the name is linked on, its name (null once the box is gone), its UUID. */ | |
| 24 | readonly boxId?: string; | |
| 25 | readonly box?: string | null; | |
| 26 | readonly uuid?: string; | |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * The account's email as an identity, in one statement. An agent's or organization's email counts | |
| 31 | * as proven (no mail reaches it, and it cannot sign in). A stand-in address (`*.invalid`) is listed | |
| 32 | * as it is stored: proven only if its maker vouched for it, as before this list. | |
| 33 | */ | |
| 34 | export function emailIdentity(db: Database, userId: string): Identity | undefined { | |
| 35 | const user = db | |
| 36 | .query< | |
| 37 | { email: string; kind: string; is_agent: number; verified_at: string | null }, | |
| 38 | [string] | |
| 39 | >( | |
| 40 | `SELECT u.email, u.kind, u.is_agent, c.verified_at | |
| 41 | FROM user u LEFT JOIN email_check c ON c.user_id = u.id WHERE u.id = ?1`, | |
| 42 | ) | |
| 43 | .get(userId); | |
| 44 | if (user === null) return undefined; | |
| 45 | const vouched = user.is_agent === 1 || user.kind === "org"; | |
| 46 | return { kind: "email", name: user.email, proven: vouched || user.verified_at !== null, since: user.verified_at }; | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * The account's Minecraft names, in one statement, oldest first. A name bound to no UUID is listed | |
| 51 | * unproven: it must be linked again. | |
| 52 | */ | |
| 53 | export const minecraftIdentities = (db: Database, userId: string): Identity[] => | |
| 54 | db | |
| 55 | .query< | |
| 56 | { boxId: string; box: string | null; player: string; uuid: string; createdAt: string }, | |
| 57 | [string] | |
| 58 | >( | |
| 59 | `SELECT l.box_id AS boxId, b.name AS box, l.player, l.uuid, l.created_at AS createdAt | |
| 60 | FROM game_link l LEFT JOIN game_box b ON b.id = l.box_id | |
| 61 | WHERE l.user_id = ?1 ORDER BY l.created_at`, | |
| 62 | ) | |
| 63 | .all(userId) | |
| 64 | .map( | |
| 65 | (r): Identity => ({ | |
| 66 | kind: "minecraft", | |
| 67 | name: r.player, | |
| 68 | proven: r.uuid !== "", | |
| 69 | since: r.createdAt, | |
| 70 | boxId: r.boxId, | |
| 71 | box: r.box, | |
| 72 | uuid: r.uuid, | |
| 73 | }), | |
| 74 | ); | |
| 75 | ||
| 76 | /** | |
| 77 | * Every identity of `userId` in one statement, email first then the Minecraft names oldest first, | |
| 78 | * and whether the forge has a game box to link a name on; no identities for an account that does | |
| 79 | * not exist. The same rows as `emailIdentity` and `minecraftIdentities`. | |
| 80 | */ | |
| 81 | export function listOf(db: Database, userId: string): { identities: Identity[]; gameBox: boolean } { | |
| 82 | const rows = db | |
| 83 | .query< | |
| 84 | { kind: IdentityKind; name: string; proven: number; since: string | null; boxId: string | null; box: string | null; uuid: string | null; gameBox: number }, | |
| 85 | [string] | |
| 86 | >( | |
| 87 | `SELECT 'email' AS kind, u.email AS name, (u.is_agent = 1 OR u.kind = 'org' OR c.verified_at IS NOT NULL) AS proven, | |
| 88 | c.verified_at AS since, NULL AS boxId, NULL AS box, NULL AS uuid, EXISTS (SELECT 1 FROM game_box) AS gameBox, 0 AS ord | |
| 89 | FROM user u LEFT JOIN email_check c ON c.user_id = u.id WHERE u.id = ?1 | |
| 90 | UNION ALL | |
| 91 | SELECT 'minecraft', l.player, l.uuid != '', l.created_at, l.box_id, b.name, l.uuid, 1, 1 | |
| 92 | FROM game_link l JOIN user u ON u.id = l.user_id LEFT JOIN game_box b ON b.id = l.box_id WHERE l.user_id = ?1 | |
| 93 | ORDER BY ord, since`, | |
| 94 | ) | |
| 95 | .all(userId); | |
| 96 | const identities = rows.map( | |
| 97 | (r): Identity => | |
| 98 | r.kind === "email" | |
| 99 | ? { kind: "email", name: r.name, proven: r.proven === 1, since: r.since } | |
| 100 | : { kind: "minecraft", name: r.name, proven: r.proven === 1, since: r.since, boxId: r.boxId ?? "", box: r.box, uuid: r.uuid ?? "" }, | |
| 101 | ); | |
| 102 | return { identities, gameBox: rows.some((r) => r.gameBox === 1) }; | |
| 103 | } | |
| 104 | ||
| 105 | /** Every identity of `userId`, email first; none for an account that does not exist. */ | |
| 106 | export const identitiesOf = (db: Database, userId: string): Identity[] => listOf(db, userId).identities; | |
| 107 | ||
| 108 | /** Whether `userId` has a proven identity of `kind`: the one read behind `emailVerified`. */ | |
| 109 | export const provenAs = (db: Database, userId: string, kind: IdentityKind): boolean => | |
| 110 | kind === "email" ? emailIdentity(db, userId)?.proven === true : minecraftIdentities(db, userId).some((i) => i.proven); | |
| 111 | ||
| 112 | /** | |
| 113 | * Remove the account's email from its list (#18160): the address becomes its stand-in | |
| 114 | * (`<username>@no-email.invalid`, as `noEmail` in `actions/users.ts` makes for an account that gave | |
| 115 | * none) and its proof is cleared. Only a person's own address; an agent's, an organization's or a | |
| 116 | * stand-in is refused. Whether it was removed. Adding one again is the profile's email field. | |
| 117 | */ | |
| 118 | export function removeEmail(db: Database, userId: string): boolean { | |
| 119 | const gone = db | |
| 120 | .query("UPDATE user SET email = lower(username) || '@no-email.invalid' WHERE id = ?1 AND kind = 'user' AND is_agent = 0 AND email NOT LIKE '%.invalid'") | |
| 121 | .run(userId).changes > 0; | |
| 122 | if (gone) db.query("UPDATE email_check SET verified_at = NULL, token_hash = NULL, expires_at = NULL WHERE user_id = ?1").run(userId); | |
| 123 | return gone; | |
| 124 | } | |
| 125 | ||
| 126 | /** What removing the email says, at both doors. */ | |
| 127 | export const REMOVED_EMAIL = "Email removed. Add one again in the profile; it starts unproven."; | |
| 128 | export const NO_EMAIL_TO_REMOVE = "There is no email of yours to remove."; | |
| 129 | /** What a remove without the address typed back says, at both doors. */ | |
| 130 | export const typeBackEmail = (email: string): string => `Type ${email} exactly to confirm. Nothing was removed.`; | |
| 131 | ||
| 132 | /** One identity as plain data for the API, with the same line both doors show. */ | |
| 133 | export const identityJson = (i: Identity): Record<string, unknown> => ({ | |
| 134 | kind: i.kind, | |
| 135 | name: i.name, | |
| 136 | proven: i.proven, | |
| 137 | since: i.since, | |
| 138 | ...(i.kind === "minecraft" ? { box: i.box ?? null, uuid: i.uuid ?? "" } : {}), | |
| 139 | line: identityLine(i), | |
| 140 | }); | |
| 141 | ||
| 142 | /** One identity as a line, the same words at both doors. */ | |
| 143 | export const identityLine = (i: Identity): string => | |
| 144 | `${i.kind === "email" ? "Email" : "Minecraft"} ${i.name}: ${i.proven ? "proven" : "unproven"}${i.kind === "minecraft" ? ` on ${i.box ?? "a box"}` : ""}`; | |
| 145 | ||
| 146 | /** | |
| 147 | * The account a Minecraft name on a box is linked to, and the UUID it is bound to: the list read | |
| 148 | * the other way. | |
| 149 | */ | |
| 150 | export const minecraftOwner = (db: Database, boxId: string, player: string): { userId: string; uuid: string } | undefined => | |
| 151 | db | |
| 152 | .query<{ userId: string; uuid: string }, [string, string]>("SELECT user_id AS userId, uuid FROM game_link WHERE box_id = ?1 AND player = ?2") | |
| 153 | .get(boxId, player) ?? undefined; |
src/core/verify.ts +3 −18
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | |
| 15 | 15 | import type { Database } from "bun:sqlite"; |
| 16 | 16 | import { sha256 } from "../kernel/hash.ts"; |
| 17 | import { provenAs } from "./proven_identities.ts"; | |
| 17 | 18 | |
| 18 | 19 | /** How long a link works. */ |
| 19 | 20 | export const LINK_TTL_MS = 24 * 3_600_000; |
| @@ -23,24 +24,8 @@ export const RESEND_AFTER_MS = 5 * 60_000; | ||
| 23 | 24 | const secret = (): string => |
| 24 | 25 | Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64url"); |
| 25 | 26 | |
| 26 | export function emailVerified(db: Database, userId: string): boolean { | |
| 27 | const row = db | |
| 28 | .query< | |
| 29 | { | |
| 30 | kind: string; | |
| 31 | is_agent: number; | |
| 32 | verified_at: string | null; | |
| 33 | }, | |
| 34 | [string] | |
| 35 | >( | |
| 36 | `SELECT u.kind, u.is_agent, c.verified_at | |
| 37 | FROM user u LEFT JOIN email_check c ON c.user_id = u.id WHERE u.id = ?1`, | |
| 38 | ) | |
| 39 | .get(userId); | |
| 40 | if (row === null) return false; | |
| 41 | if (row.is_agent === 1 || row.kind === "org") return true; | |
| 42 | return row.verified_at !== null; | |
| 43 | } | |
| 27 | /** Whether the account's email is proven: read from its one list of identities (#18160). */ | |
| 28 | export const emailVerified = (db: Database, userId: string): boolean => provenAs(db, userId, "email"); | |
| 44 | 29 | |
| 45 | 30 | /** A new account's row: unproven until a link is followed or an owner says so. */ |
| 46 | 31 | export function markUnproven(db: Database, userId: string): void { |
src/games/chat.ts +15 −28
| @@ -32,6 +32,7 @@ import { createConversation, listTurns } from "../core/conversations.ts"; | ||
| 32 | 32 | import { proveMinecraft, unproveMinecraft } from "../core/identities.ts"; |
| 33 | 33 | import { readReceipt } from "../crew/receipt.ts"; |
| 34 | 34 | import { publicOrigin } from "../core/public_origin.ts"; |
| 35 | import { minecraftIdentities, minecraftOwner } from "../core/proven_identities.ts"; | |
| 35 | 36 | import { getUserById, isActive, type User } from "../core/users.ts"; |
| 36 | 37 | import { blockedBy, blockedText } from "../kernel/blocked.ts"; |
| 37 | 38 | import { sha256 } from "../kernel/hash.ts"; |
| @@ -149,33 +150,21 @@ export function newLinkCode(app: App, user: User, now = Date.now()): string | un | ||
| 149 | 150 | export const onlineUuid = (app: App, boxId: string, service: string, player: string): string => |
| 150 | 151 | peopleOf(app.db, boxId, service).online.find((p) => p.name === player)?.uuid ?? ""; |
| 151 | 152 | |
| 152 | /** The player names linked to `userId`, on every box, each with the UUID it is bound to. */ | |
| 153 | export const linksOf = (app: App, userId: string): { boxId: string; player: string; uuid: string; createdAt: string }[] => | |
| 154 | app.db | |
| 155 | .query< | |
| 156 | { boxId: string; player: string; uuid: string; createdAt: string }, | |
| 157 | [string] | |
| 158 | >("SELECT box_id AS boxId, player, uuid, created_at AS createdAt FROM game_link WHERE user_id = ?1 ORDER BY created_at") | |
| 159 | .all(userId); | |
| 153 | /** | |
| 154 | * The player names linked to `userId`, on every box, each with the UUID it is bound to: its | |
| 155 | * Minecraft identities (#18160). | |
| 156 | */ | |
| 157 | export const linksOf = (app: App, userId: string): { boxId: string; box: string | null; player: string; uuid: string; createdAt: string }[] => | |
| 158 | minecraftIdentities(app.db, userId).map((i) => ({ boxId: i.boxId ?? "", box: i.box ?? null, player: i.name, uuid: i.uuid ?? "", createdAt: i.since ?? "" })); | |
| 160 | 159 | |
| 161 | 160 | /** |
| 162 | * The account page's links in one statement, each with its box's name; undefined where there is no | |
| 163 | * game box to link a name on. A link gives no role, so the button is for everyone signed in. | |
| 161 | * The account page's links, each with its box's name, read from the list (`linksOf`); undefined | |
| 162 | * where there is no game box to link a name on and none linked. A link gives no role, so the button | |
| 163 | * is for everyone signed in. | |
| 164 | 164 | */ |
| 165 | 165 | export function accountLinks(app: App, user: User): { boxId: string; box: string | null; player: string; uuid: string; createdAt: string }[] | undefined { |
| 166 | const rows = app.db | |
| 167 | .query< | |
| 168 | { boxId: string; box: string | null; player: string | null; uuid: string; createdAt: string }, | |
| 169 | [string] | |
| 170 | >( | |
| 171 | `SELECT l.box_id AS boxId, b.name AS box, l.player, l.uuid, l.created_at AS createdAt | |
| 172 | FROM (SELECT 1) LEFT JOIN game_link l ON l.user_id = ?1 LEFT JOIN game_box b ON b.id = l.box_id | |
| 173 | WHERE l.player IS NOT NULL | |
| 174 | OR EXISTS (SELECT 1 FROM game_box) | |
| 175 | ORDER BY l.created_at`, | |
| 176 | ) | |
| 177 | .all(user.id); | |
| 178 | return rows.length === 0 ? undefined : rows.flatMap((r) => (r.player === null ? [] : [{ ...r, player: r.player }])); | |
| 166 | const links = linksOf(app, user.id); | |
| 167 | return links.length > 0 || app.db.query("SELECT 1 FROM game_box LIMIT 1").get() !== null ? links : undefined; | |
| 179 | 168 | } |
| 180 | 169 | |
| 181 | 170 | /** Who is linked on a box: the player name, the forge account, since when. */ |
| @@ -432,13 +421,11 @@ function one( | ||
| 432 | 421 | "green", |
| 433 | 422 | ); |
| 434 | 423 | } |
| 435 | const linked = db | |
| 436 | .query<{ user_id: string; uuid: string }, [string, string]>("SELECT user_id, uuid FROM game_link WHERE box_id = ?1 AND player = ?2") | |
| 437 | .get(box.id, player); | |
| 438 | const user = linked === null ? undefined : getUserById(db, linked.user_id); | |
| 424 | const linked = minecraftOwner(db, box.id, player); | |
| 425 | const user = linked === undefined ? undefined : getUserById(db, linked.userId); | |
| 439 | 426 | // The link is a credential like any other: a suspended or removed account's says nothing. |
| 440 | 427 | if (user !== undefined && !isActive(user)) return refuse(user.id, "account not active", "The forge account this name is linked to cannot act now."); |
| 441 | if (linked !== null && user !== undefined) { | |
| 428 | if (linked !== undefined && user !== undefined) { | |
| 442 | 429 | // The name is only the account's while it is the same player: the UUID the server lists for it |
| 443 | 430 | // now. |
| 444 | 431 | const uuid = uuidNow(); |
src/generated/marks.ts +172 −170
| @@ -49,176 +49,177 @@ import k44 from "../http/marks/api-v1-health.json"; | ||
| 49 | 49 | import k45 from "../http/marks/api-v1-heartbeat.json"; |
| 50 | 50 | import k46 from "../http/marks/api-v1-here.json"; |
| 51 | 51 | import k47 from "../http/marks/api-v1-home.json"; |
| 52 | import k48 from "../http/marks/api-v1-keeper.json"; | |
| 53 | import k49 from "../http/marks/api-v1-mail-aws.json"; | |
| 54 | import k50 from "../http/marks/api-v1-mail-key.json"; | |
| 55 | import k51 from "../http/marks/api-v1-maintenance.json"; | |
| 56 | import k52 from "../http/marks/api-v1-map.json"; | |
| 57 | import k53 from "../http/marks/api-v1-may.json"; | |
| 58 | import k54 from "../http/marks/api-v1-migrate.json"; | |
| 59 | import k55 from "../http/marks/api-v1-models.json"; | |
| 60 | import k56 from "../http/marks/api-v1-offers.json"; | |
| 61 | import k57 from "../http/marks/api-v1-openapi.json.json"; | |
| 62 | import k58 from "../http/marks/api-v1-orgs.json"; | |
| 63 | import k59 from "../http/marks/api-v1-packs.json"; | |
| 64 | import k60 from "../http/marks/api-v1-passport.json"; | |
| 65 | import k61 from "../http/marks/api-v1-places.json"; | |
| 66 | import k62 from "../http/marks/api-v1-plans.json"; | |
| 67 | import k63 from "../http/marks/api-v1-proof.json"; | |
| 68 | import k64 from "../http/marks/api-v1-reach.json"; | |
| 69 | import k65 from "../http/marks/api-v1-release.json"; | |
| 70 | import k66 from "../http/marks/api-v1-releases.json"; | |
| 71 | import k67 from "../http/marks/api-v1-repos.json"; | |
| 72 | import k68 from "../http/marks/api-v1-returns.json"; | |
| 73 | import k69 from "../http/marks/api-v1-runner.json"; | |
| 74 | import k70 from "../http/marks/api-v1-search.json"; | |
| 75 | import k71 from "../http/marks/api-v1-secrets.json"; | |
| 76 | import k72 from "../http/marks/api-v1-sessions.json"; | |
| 77 | import k73 from "../http/marks/api-v1-share.json"; | |
| 78 | import k74 from "../http/marks/api-v1-slash.json"; | |
| 79 | import k75 from "../http/marks/api-v1-start.json"; | |
| 80 | import k76 from "../http/marks/api-v1-status.json"; | |
| 81 | import k77 from "../http/marks/api-v1-telemetry.json"; | |
| 82 | import k78 from "../http/marks/api-v1-templates.json"; | |
| 83 | import k79 from "../http/marks/api-v1-thoughts.json"; | |
| 84 | import k80 from "../http/marks/api-v1-timers.json"; | |
| 85 | import k81 from "../http/marks/api-v1-tokens.json"; | |
| 86 | import k82 from "../http/marks/api-v1-usage.json"; | |
| 87 | import k83 from "../http/marks/api-v1-user.json"; | |
| 88 | import k84 from "../http/marks/api-v1-users.json"; | |
| 89 | import k85 from "../http/marks/api-v1-version.json"; | |
| 90 | import k86 from "../http/marks/api-v1.json"; | |
| 91 | import k87 from "../http/marks/api.json"; | |
| 92 | import k88 from "../http/marks/apple-touch-icon-precomposed.png.json"; | |
| 93 | import k89 from "../http/marks/apple-touch-icon.png.json"; | |
| 94 | import k90 from "../http/marks/apps.json"; | |
| 95 | import k91 from "../http/marks/archive.json"; | |
| 96 | import k92 from "../http/marks/asked.json"; | |
| 97 | import k93 from "../http/marks/asks.json"; | |
| 98 | import k94 from "../http/marks/assets.json"; | |
| 99 | import k95 from "../http/marks/audit.csv.json"; | |
| 100 | import k96 from "../http/marks/audit.json"; | |
| 101 | import k97 from "../http/marks/big.json"; | |
| 102 | import k98 from "../http/marks/board.json"; | |
| 103 | import k99 from "../http/marks/boards.json"; | |
| 104 | import k100 from "../http/marks/bring.json"; | |
| 105 | import k101 from "../http/marks/broker.json"; | |
| 106 | import k102 from "../http/marks/changelog.atom.json"; | |
| 107 | import k103 from "../http/marks/changelog.json"; | |
| 108 | import k104 from "../http/marks/claim.json"; | |
| 109 | import k105 from "../http/marks/client-clouds.json"; | |
| 110 | import k106 from "../http/marks/cloud.json"; | |
| 111 | import k107 from "../http/marks/cockpit.json"; | |
| 112 | import k108 from "../http/marks/contract.json"; | |
| 113 | import k109 from "../http/marks/contribute.json"; | |
| 114 | import k110 from "../http/marks/csp-report.json"; | |
| 115 | import k111 from "../http/marks/dash.json"; | |
| 116 | import k112 from "../http/marks/data.json"; | |
| 117 | import k113 from "../http/marks/dataset.json"; | |
| 118 | import k114 from "../http/marks/deploy-to.json"; | |
| 119 | import k115 from "../http/marks/design.json"; | |
| 120 | import k116 from "../http/marks/desk.json"; | |
| 121 | import k117 from "../http/marks/displays.json"; | |
| 122 | import k118 from "../http/marks/docs.json"; | |
| 123 | import k119 from "../http/marks/edge.json"; | |
| 124 | import k120 from "../http/marks/edition.json"; | |
| 125 | import k121 from "../http/marks/events.json"; | |
| 126 | import k122 from "../http/marks/explore.atom.json"; | |
| 127 | import k123 from "../http/marks/explore.json"; | |
| 128 | import k124 from "../http/marks/explore.json.json"; | |
| 129 | import k125 from "../http/marks/family.json"; | |
| 130 | import k126 from "../http/marks/favicon.ico.json"; | |
| 131 | import k127 from "../http/marks/feed.json"; | |
| 132 | import k128 from "../http/marks/feed.json.json"; | |
| 133 | import k129 from "../http/marks/first-admin.json"; | |
| 134 | import k130 from "../http/marks/fleet.json"; | |
| 135 | import k131 from "../http/marks/flow.json"; | |
| 136 | import k132 from "../http/marks/forge.json"; | |
| 137 | import k133 from "../http/marks/forges.json"; | |
| 138 | import k134 from "../http/marks/forks.json"; | |
| 139 | import k135 from "../http/marks/front.json"; | |
| 140 | import k136 from "../http/marks/funnel.json"; | |
| 141 | import k137 from "../http/marks/games.json"; | |
| 142 | import k138 from "../http/marks/go.json"; | |
| 143 | import k139 from "../http/marks/health.json"; | |
| 144 | import k140 from "../http/marks/home.json"; | |
| 145 | import k141 from "../http/marks/hooks.json"; | |
| 146 | import k142 from "../http/marks/icons.json"; | |
| 147 | import k143 from "../http/marks/infra.json"; | |
| 148 | import k144 from "../http/marks/join.json"; | |
| 149 | import k145 from "../http/marks/live.json"; | |
| 150 | import k146 from "../http/marks/llms-full.txt.json"; | |
| 151 | import k147 from "../http/marks/llms.txt.json"; | |
| 152 | import k148 from "../http/marks/login.json"; | |
| 153 | import k149 from "../http/marks/logout.json"; | |
| 154 | import k150 from "../http/marks/maintenance-json.json"; | |
| 155 | import k151 from "../http/marks/maintenance.json"; | |
| 156 | import k152 from "../http/marks/manifest.webmanifest.json"; | |
| 157 | import k153 from "../http/marks/map.json"; | |
| 158 | import k154 from "../http/marks/mcp.json"; | |
| 159 | import k155 from "../http/marks/measure.json"; | |
| 160 | import k156 from "../http/marks/metrics.json"; | |
| 161 | import k157 from "../http/marks/migrate.json"; | |
| 162 | import k158 from "../http/marks/new.json"; | |
| 163 | import k159 from "../http/marks/next.json"; | |
| 164 | import k160 from "../http/marks/notes.json"; | |
| 165 | import k161 from "../http/marks/now.json"; | |
| 166 | import k162 from "../http/marks/oauth.json"; | |
| 167 | import k163 from "../http/marks/oembed.json"; | |
| 168 | import k164 from "../http/marks/offers.json"; | |
| 169 | import k165 from "../http/marks/offline.json"; | |
| 170 | import k166 from "../http/marks/og.json"; | |
| 171 | import k167 from "../http/marks/openapi.json.json"; | |
| 172 | import k168 from "../http/marks/opensearch.xml.json"; | |
| 173 | import k169 from "../http/marks/organizations.json"; | |
| 174 | import k170 from "../http/marks/origins.json"; | |
| 175 | import k171 from "../http/marks/owner.atom.json"; | |
| 176 | import k172 from "../http/marks/owner.json"; | |
| 177 | import k173 from "../http/marks/packs.json"; | |
| 178 | import k174 from "../http/marks/peek.json"; | |
| 179 | import k175 from "../http/marks/pinned.json"; | |
| 180 | import k176 from "../http/marks/pipeline.json"; | |
| 181 | import k177 from "../http/marks/plugins.json"; | |
| 182 | import k178 from "../http/marks/pricing.json"; | |
| 183 | import k179 from "../http/marks/privacy.json"; | |
| 184 | import k180 from "../http/marks/r.json"; | |
| 185 | import k181 from "../http/marks/recover.json"; | |
| 186 | import k182 from "../http/marks/releases.json"; | |
| 187 | import k183 from "../http/marks/releases.json.json"; | |
| 188 | import k184 from "../http/marks/repos.json"; | |
| 189 | import k185 from "../http/marks/resilience.json"; | |
| 190 | import k186 from "../http/marks/review.json"; | |
| 191 | import k187 from "../http/marks/robots.txt.json"; | |
| 192 | import k188 from "../http/marks/root.json"; | |
| 193 | import k189 from "../http/marks/runs.json"; | |
| 194 | import k190 from "../http/marks/script-error.json"; | |
| 195 | import k191 from "../http/marks/search.json"; | |
| 196 | import k192 from "../http/marks/security.json"; | |
| 197 | import k193 from "../http/marks/settings.json"; | |
| 198 | import k194 from "../http/marks/sign-in.json"; | |
| 199 | import k195 from "../http/marks/signin.json"; | |
| 200 | import k196 from "../http/marks/signup.json"; | |
| 201 | import k197 from "../http/marks/sitemap.xml.json"; | |
| 202 | import k198 from "../http/marks/status.json"; | |
| 203 | import k199 from "../http/marks/support.json"; | |
| 204 | import k200 from "../http/marks/sw.js.json"; | |
| 205 | import k201 from "../http/marks/system.json"; | |
| 206 | import k202 from "../http/marks/tab.json"; | |
| 207 | import k203 from "../http/marks/tabforge-link.json"; | |
| 208 | import k204 from "../http/marks/tabforge-move.json"; | |
| 209 | import k205 from "../http/marks/tabforge.json"; | |
| 210 | import k206 from "../http/marks/talk.json"; | |
| 211 | import k207 from "../http/marks/tell.json"; | |
| 212 | import k208 from "../http/marks/templates.json"; | |
| 213 | import k209 from "../http/marks/templates.json.json"; | |
| 214 | import k210 from "../http/marks/terms.json"; | |
| 215 | import k211 from "../http/marks/theme.json"; | |
| 216 | import k212 from "../http/marks/toolbar-lab.js.json"; | |
| 217 | import k213 from "../http/marks/toolbar-lab.json"; | |
| 218 | import k214 from "../http/marks/traces.json"; | |
| 219 | import k215 from "../http/marks/verify.json"; | |
| 220 | import k216 from "../http/marks/welcome.json"; | |
| 221 | import k217 from "../http/marks/well-known.json"; | |
| 52 | import k48 from "../http/marks/api-v1-identities.json"; | |
| 53 | import k49 from "../http/marks/api-v1-keeper.json"; | |
| 54 | import k50 from "../http/marks/api-v1-mail-aws.json"; | |
| 55 | import k51 from "../http/marks/api-v1-mail-key.json"; | |
| 56 | import k52 from "../http/marks/api-v1-maintenance.json"; | |
| 57 | import k53 from "../http/marks/api-v1-map.json"; | |
| 58 | import k54 from "../http/marks/api-v1-may.json"; | |
| 59 | import k55 from "../http/marks/api-v1-migrate.json"; | |
| 60 | import k56 from "../http/marks/api-v1-models.json"; | |
| 61 | import k57 from "../http/marks/api-v1-offers.json"; | |
| 62 | import k58 from "../http/marks/api-v1-openapi.json.json"; | |
| 63 | import k59 from "../http/marks/api-v1-orgs.json"; | |
| 64 | import k60 from "../http/marks/api-v1-packs.json"; | |
| 65 | import k61 from "../http/marks/api-v1-passport.json"; | |
| 66 | import k62 from "../http/marks/api-v1-places.json"; | |
| 67 | import k63 from "../http/marks/api-v1-plans.json"; | |
| 68 | import k64 from "../http/marks/api-v1-proof.json"; | |
| 69 | import k65 from "../http/marks/api-v1-reach.json"; | |
| 70 | import k66 from "../http/marks/api-v1-release.json"; | |
| 71 | import k67 from "../http/marks/api-v1-releases.json"; | |
| 72 | import k68 from "../http/marks/api-v1-repos.json"; | |
| 73 | import k69 from "../http/marks/api-v1-returns.json"; | |
| 74 | import k70 from "../http/marks/api-v1-runner.json"; | |
| 75 | import k71 from "../http/marks/api-v1-search.json"; | |
| 76 | import k72 from "../http/marks/api-v1-secrets.json"; | |
| 77 | import k73 from "../http/marks/api-v1-sessions.json"; | |
| 78 | import k74 from "../http/marks/api-v1-share.json"; | |
| 79 | import k75 from "../http/marks/api-v1-slash.json"; | |
| 80 | import k76 from "../http/marks/api-v1-start.json"; | |
| 81 | import k77 from "../http/marks/api-v1-status.json"; | |
| 82 | import k78 from "../http/marks/api-v1-telemetry.json"; | |
| 83 | import k79 from "../http/marks/api-v1-templates.json"; | |
| 84 | import k80 from "../http/marks/api-v1-thoughts.json"; | |
| 85 | import k81 from "../http/marks/api-v1-timers.json"; | |
| 86 | import k82 from "../http/marks/api-v1-tokens.json"; | |
| 87 | import k83 from "../http/marks/api-v1-usage.json"; | |
| 88 | import k84 from "../http/marks/api-v1-user.json"; | |
| 89 | import k85 from "../http/marks/api-v1-users.json"; | |
| 90 | import k86 from "../http/marks/api-v1-version.json"; | |
| 91 | import k87 from "../http/marks/api-v1.json"; | |
| 92 | import k88 from "../http/marks/api.json"; | |
| 93 | import k89 from "../http/marks/apple-touch-icon-precomposed.png.json"; | |
| 94 | import k90 from "../http/marks/apple-touch-icon.png.json"; | |
| 95 | import k91 from "../http/marks/apps.json"; | |
| 96 | import k92 from "../http/marks/archive.json"; | |
| 97 | import k93 from "../http/marks/asked.json"; | |
| 98 | import k94 from "../http/marks/asks.json"; | |
| 99 | import k95 from "../http/marks/assets.json"; | |
| 100 | import k96 from "../http/marks/audit.csv.json"; | |
| 101 | import k97 from "../http/marks/audit.json"; | |
| 102 | import k98 from "../http/marks/big.json"; | |
| 103 | import k99 from "../http/marks/board.json"; | |
| 104 | import k100 from "../http/marks/boards.json"; | |
| 105 | import k101 from "../http/marks/bring.json"; | |
| 106 | import k102 from "../http/marks/broker.json"; | |
| 107 | import k103 from "../http/marks/changelog.atom.json"; | |
| 108 | import k104 from "../http/marks/changelog.json"; | |
| 109 | import k105 from "../http/marks/claim.json"; | |
| 110 | import k106 from "../http/marks/client-clouds.json"; | |
| 111 | import k107 from "../http/marks/cloud.json"; | |
| 112 | import k108 from "../http/marks/cockpit.json"; | |
| 113 | import k109 from "../http/marks/contract.json"; | |
| 114 | import k110 from "../http/marks/contribute.json"; | |
| 115 | import k111 from "../http/marks/csp-report.json"; | |
| 116 | import k112 from "../http/marks/dash.json"; | |
| 117 | import k113 from "../http/marks/data.json"; | |
| 118 | import k114 from "../http/marks/dataset.json"; | |
| 119 | import k115 from "../http/marks/deploy-to.json"; | |
| 120 | import k116 from "../http/marks/design.json"; | |
| 121 | import k117 from "../http/marks/desk.json"; | |
| 122 | import k118 from "../http/marks/displays.json"; | |
| 123 | import k119 from "../http/marks/docs.json"; | |
| 124 | import k120 from "../http/marks/edge.json"; | |
| 125 | import k121 from "../http/marks/edition.json"; | |
| 126 | import k122 from "../http/marks/events.json"; | |
| 127 | import k123 from "../http/marks/explore.atom.json"; | |
| 128 | import k124 from "../http/marks/explore.json"; | |
| 129 | import k125 from "../http/marks/explore.json.json"; | |
| 130 | import k126 from "../http/marks/family.json"; | |
| 131 | import k127 from "../http/marks/favicon.ico.json"; | |
| 132 | import k128 from "../http/marks/feed.json"; | |
| 133 | import k129 from "../http/marks/feed.json.json"; | |
| 134 | import k130 from "../http/marks/first-admin.json"; | |
| 135 | import k131 from "../http/marks/fleet.json"; | |
| 136 | import k132 from "../http/marks/flow.json"; | |
| 137 | import k133 from "../http/marks/forge.json"; | |
| 138 | import k134 from "../http/marks/forges.json"; | |
| 139 | import k135 from "../http/marks/forks.json"; | |
| 140 | import k136 from "../http/marks/front.json"; | |
| 141 | import k137 from "../http/marks/funnel.json"; | |
| 142 | import k138 from "../http/marks/games.json"; | |
| 143 | import k139 from "../http/marks/go.json"; | |
| 144 | import k140 from "../http/marks/health.json"; | |
| 145 | import k141 from "../http/marks/home.json"; | |
| 146 | import k142 from "../http/marks/hooks.json"; | |
| 147 | import k143 from "../http/marks/icons.json"; | |
| 148 | import k144 from "../http/marks/infra.json"; | |
| 149 | import k145 from "../http/marks/join.json"; | |
| 150 | import k146 from "../http/marks/live.json"; | |
| 151 | import k147 from "../http/marks/llms-full.txt.json"; | |
| 152 | import k148 from "../http/marks/llms.txt.json"; | |
| 153 | import k149 from "../http/marks/login.json"; | |
| 154 | import k150 from "../http/marks/logout.json"; | |
| 155 | import k151 from "../http/marks/maintenance-json.json"; | |
| 156 | import k152 from "../http/marks/maintenance.json"; | |
| 157 | import k153 from "../http/marks/manifest.webmanifest.json"; | |
| 158 | import k154 from "../http/marks/map.json"; | |
| 159 | import k155 from "../http/marks/mcp.json"; | |
| 160 | import k156 from "../http/marks/measure.json"; | |
| 161 | import k157 from "../http/marks/metrics.json"; | |
| 162 | import k158 from "../http/marks/migrate.json"; | |
| 163 | import k159 from "../http/marks/new.json"; | |
| 164 | import k160 from "../http/marks/next.json"; | |
| 165 | import k161 from "../http/marks/notes.json"; | |
| 166 | import k162 from "../http/marks/now.json"; | |
| 167 | import k163 from "../http/marks/oauth.json"; | |
| 168 | import k164 from "../http/marks/oembed.json"; | |
| 169 | import k165 from "../http/marks/offers.json"; | |
| 170 | import k166 from "../http/marks/offline.json"; | |
| 171 | import k167 from "../http/marks/og.json"; | |
| 172 | import k168 from "../http/marks/openapi.json.json"; | |
| 173 | import k169 from "../http/marks/opensearch.xml.json"; | |
| 174 | import k170 from "../http/marks/organizations.json"; | |
| 175 | import k171 from "../http/marks/origins.json"; | |
| 176 | import k172 from "../http/marks/owner.atom.json"; | |
| 177 | import k173 from "../http/marks/owner.json"; | |
| 178 | import k174 from "../http/marks/packs.json"; | |
| 179 | import k175 from "../http/marks/peek.json"; | |
| 180 | import k176 from "../http/marks/pinned.json"; | |
| 181 | import k177 from "../http/marks/pipeline.json"; | |
| 182 | import k178 from "../http/marks/plugins.json"; | |
| 183 | import k179 from "../http/marks/pricing.json"; | |
| 184 | import k180 from "../http/marks/privacy.json"; | |
| 185 | import k181 from "../http/marks/r.json"; | |
| 186 | import k182 from "../http/marks/recover.json"; | |
| 187 | import k183 from "../http/marks/releases.json"; | |
| 188 | import k184 from "../http/marks/releases.json.json"; | |
| 189 | import k185 from "../http/marks/repos.json"; | |
| 190 | import k186 from "../http/marks/resilience.json"; | |
| 191 | import k187 from "../http/marks/review.json"; | |
| 192 | import k188 from "../http/marks/robots.txt.json"; | |
| 193 | import k189 from "../http/marks/root.json"; | |
| 194 | import k190 from "../http/marks/runs.json"; | |
| 195 | import k191 from "../http/marks/script-error.json"; | |
| 196 | import k192 from "../http/marks/search.json"; | |
| 197 | import k193 from "../http/marks/security.json"; | |
| 198 | import k194 from "../http/marks/settings.json"; | |
| 199 | import k195 from "../http/marks/sign-in.json"; | |
| 200 | import k196 from "../http/marks/signin.json"; | |
| 201 | import k197 from "../http/marks/signup.json"; | |
| 202 | import k198 from "../http/marks/sitemap.xml.json"; | |
| 203 | import k199 from "../http/marks/status.json"; | |
| 204 | import k200 from "../http/marks/support.json"; | |
| 205 | import k201 from "../http/marks/sw.js.json"; | |
| 206 | import k202 from "../http/marks/system.json"; | |
| 207 | import k203 from "../http/marks/tab.json"; | |
| 208 | import k204 from "../http/marks/tabforge-link.json"; | |
| 209 | import k205 from "../http/marks/tabforge-move.json"; | |
| 210 | import k206 from "../http/marks/tabforge.json"; | |
| 211 | import k207 from "../http/marks/talk.json"; | |
| 212 | import k208 from "../http/marks/tell.json"; | |
| 213 | import k209 from "../http/marks/templates.json"; | |
| 214 | import k210 from "../http/marks/templates.json.json"; | |
| 215 | import k211 from "../http/marks/terms.json"; | |
| 216 | import k212 from "../http/marks/theme.json"; | |
| 217 | import k213 from "../http/marks/toolbar-lab.js.json"; | |
| 218 | import k214 from "../http/marks/toolbar-lab.json"; | |
| 219 | import k215 from "../http/marks/traces.json"; | |
| 220 | import k216 from "../http/marks/verify.json"; | |
| 221 | import k217 from "../http/marks/welcome.json"; | |
| 222 | import k218 from "../http/marks/well-known.json"; | |
| 222 | 223 | |
| 223 | 224 | /** Each file of `http/marks/`, parsed, in name order. */ |
| 224 | 225 | export const MARK_FILES: readonly unknown[] = [ |
| @@ -440,4 +441,5 @@ export const MARK_FILES: readonly unknown[] = [ | ||
| 440 | 441 | k215, |
| 441 | 442 | k216, |
| 442 | 443 | k217, |
| 444 | k218, | |
| 443 | 445 | ]; |
src/http/api/user.ts +10
| @@ -25,6 +25,7 @@ import { canRead, getRepo, getReposByIds, readableRepoIds } from "../../core/rep | ||
| 25 | 25 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; |
| 26 | 26 | import { mayView } from "../../core/sealed.ts"; |
| 27 | 27 | import { emailVerified, RESEND_AFTER_MS } from "../../core/verify.ts"; |
| 28 | import { identitiesOf, identityJson } from "../../core/proven_identities.ts"; | |
| 28 | 29 | import type { Result } from "../../kernel/result.ts"; |
| 29 | 30 | import { subscribe as subscribeJob } from "../../origins/jobs.ts"; |
| 30 | 31 | import { sshCloneUrl } from "../../ssh/command.ts"; |
| @@ -126,6 +127,15 @@ export function userRoutes(router: Router<Handler>): void { | ||
| 126 | 127 | return timePhase(ctx.request, "render", () => json({ ...publicUser(me), emailVerified: verified, can: capabilities(ctx.app.db, principalOf(ctx.auth)) })); |
| 127 | 128 | }); |
| 128 | 129 | |
| 130 | // Who you are, in one list (#18160): the same identities, words and proof as Settings and the | |
| 131 | // terminal's profile. | |
| 132 | router.add("GET", "/api/v1/identities", (ctx) => { | |
| 133 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 134 | const me = ctx.auth.user; | |
| 135 | if (!me) return unauthorized(); | |
| 136 | return json({ identities: identitiesOf(ctx.app.db, me.id).map(identityJson) }); | |
| 137 | }); | |
| 138 | ||
| 129 | 139 | // Another verification link for the signed-in account; rate limited. |
| 130 | 140 | router.add("POST", "/api/v1/user/email/verify", async (ctx) => { |
| 131 | 141 | if (!ctx.auth.user) return unauthorized(); |
src/http/lazy_lists.ts +2
| @@ -54,6 +54,7 @@ export const SETTINGS_ROUTES = [ | ||
| 54 | 54 | ["POST", "/settings/parent/link"], |
| 55 | 55 | ["POST", "/settings/parent/unlink"], |
| 56 | 56 | ["POST", "/settings/email/verify"], |
| 57 | ["POST", "/settings/email/remove"], | |
| 57 | 58 | ["GET", "/settings/password"], |
| 58 | 59 | ["POST", "/settings/password"], |
| 59 | 60 | ["GET", "/settings/everyday"], |
| @@ -1228,6 +1229,7 @@ export const API_ROUTES = [ | ||
| 1228 | 1229 | ["GET", "/api/v1/tokens"], |
| 1229 | 1230 | ["DELETE", "/api/v1/tokens/:id"], |
| 1230 | 1231 | ["GET", "/api/v1/user"], |
| 1232 | ["GET", "/api/v1/identities"], | |
| 1231 | 1233 | ["POST", "/api/v1/user/email/verify"], |
| 1232 | 1234 | ["PATCH", "/api/v1/user"], |
| 1233 | 1235 | ["POST", "/api/v1/user/password"], |
src/http/marks/api-v1-identities.json added +4
src/http/marks/settings.json +1
src/http/settings_routes.ts +2
| @@ -13,6 +13,7 @@ import { fallbackCapSave, fallbackSave } from "../web/studio/crew_fallback.ts"; | ||
| 13 | 13 | import type { Handler } from "./context.ts"; |
| 14 | 14 | import type { Router } from "./router.ts"; |
| 15 | 15 | import { parentLinkStart } from "./rp.ts"; |
| 16 | import { emailRemove } from "../web/pages/proven_identities.ts"; | |
| 16 | 17 | import { accessPage } from "../web/pages/access.ts"; |
| 17 | 18 | import { whoCanPage } from "../web/pages/who-can.ts"; |
| 18 | 19 | import { knobSet } from "../web/pages/knobs.ts"; |
| @@ -204,6 +205,7 @@ export function settingsRoutes(router: Router<Handler>, knownPatterns: () => rea | ||
| 204 | 205 | router.add("POST", "/settings/parent/link", parentLinkStart); |
| 205 | 206 | router.add("POST", "/settings/parent/unlink", parentUnlink); |
| 206 | 207 | router.add("POST", "/settings/email/verify", resendVerifyLink); |
| 208 | router.add("POST", "/settings/email/remove", emailRemove); | |
| 207 | 209 | router.add("GET", "/settings/password", passwordPage); |
| 208 | 210 | router.add("POST", "/settings/password", passwordUpdate); |
| 209 | 211 | // The everyday account: an admin's daily account, apart from admin (#596). |
src/tui/screens/profile.ts +70 −3
| @@ -5,17 +5,21 @@ | ||
| 5 | 5 | * verification exactly as it does on the web. The last row counts the one-file |
| 6 | 6 | * export of the account (#15617), and `x` says the exec that writes it to the |
| 7 | 7 | * person's own machine (`ssh … export > file`, `serveExport` in `src/core/account_export.ts`): a |
| 8 | * file written here would land on the forge's disk, not theirs. | |
| 8 | * file written here would land on the forge's disk, not theirs. Identities (#18160) lists who you | |
| 9 | * are, as Settings does: `r` removes the email, `l` gives a code to link a Minecraft name, `u` | |
| 10 | * unlinks one. | |
| 9 | 11 | */ |
| 10 | 12 | |
| 11 | 13 | import { invalidEmailMessage } from "../../actions/users.ts"; |
| 12 | 14 | import { emailSavedWords, PROFILE_FALLBACK, PROFILE_REFUSALS } from "../../actions/profile_words.ts"; |
| 13 | 15 | import { askToClose, CLOSE_WORDS, closeRequestedAt, closesOn, closingSays, GRACE_DAYS, keepMyAccount, keptSays } from "../../actions/account_close.ts"; |
| 14 | 16 | import { updateProfile } from "../../actions/users.ts"; |
| 17 | import { identitiesOf, identityLine, NO_EMAIL_TO_REMOVE, REMOVED_EMAIL, removeEmail, typeBackEmail } from "../../core/proven_identities.ts"; | |
| 18 | import { accountLinks, newLinkCode, NO_LINK_HERE, unlink } from "../../games/chat.ts"; | |
| 15 | 19 | import { EXPORT_EXEC, EXPORT_PATH, EXPORT_WORDS, exportCounts, exportFileName } from "../../core/account_export.ts"; |
| 16 | 20 | import { sshCommand } from "../../ssh/command.ts"; |
| 17 | 21 | import type { Database } from "bun:sqlite"; |
| 18 | import { isStandInEmail, type User } from "../../core/users.ts"; | |
| 22 | import { getUserById, isStandInEmail, type User } from "../../core/users.ts"; | |
| 19 | 23 | import type { Ctx, Screen } from "../app/app.ts"; |
| 20 | 24 | import { binding } from "../app/keys.ts"; |
| 21 | 25 | import type { Session } from "../session.ts"; |
| @@ -91,7 +95,7 @@ export function profileScreen(f: Session, ctx: Ctx): Screen { | ||
| 91 | 95 | const held = exportWords(f.app.db, f.user); |
| 92 | 96 | const screen: Screen = { |
| 93 | 97 | title: "Your profile", |
| 94 | keys: [binding(["n"], "set display name"), binding(["e"], "set email"), binding(["x"], "take my data"), binding(["c"], "close account"), binding(["k"], "keep account")], | |
| 98 | keys: [binding(["n"], "set display name"), binding(["e"], "set email"), binding(["r"], "remove email"), binding(["l"], "link Minecraft name"), binding(["u"], "unlink Minecraft name"), binding(["x"], "take my data"), binding(["c"], "close account"), binding(["k"], "keep account")], | |
| 95 | 99 | render(area, s) { |
| 96 | 100 | const c = ctx.theme.c; |
| 97 | 101 | const u = f.user; |
| @@ -103,6 +107,11 @@ export function profileScreen(f: Session, ctx: Ctx): Screen { | ||
| 103 | 107 | ["Display name", u.displayName], |
| 104 | 108 | ["Email", email], |
| 105 | 109 | ["Your data", held], |
| 110 | // Who you are, in one list, each proven or not: what the Identities block on /settings | |
| 111 | // shows (#18160). | |
| 112 | ...identitiesOf(f.app.db, u.id) | |
| 113 | .filter((i) => !(i.kind === "email" && isStandInEmail(i.name))) | |
| 114 | .map((i, n): [string, string] => [n === 0 ? "Identities" : "", identityLine(i)]), | |
| 106 | 115 | ...(closing === null ? [] : [["Closing", `closes on ${closesOn(closing)}; k keeps it`] as [string, string]]), |
| 107 | 116 | ]; |
| 108 | 117 | rows.forEach(([k, v], i) => { |
| @@ -133,6 +142,64 @@ export function profileScreen(f: Session, ctx: Ctx): Screen { | ||
| 133 | 142 | ctx.invalidate(); |
| 134 | 143 | return true; |
| 135 | 144 | } |
| 145 | // Add or remove an identity, as the Identities block on /settings does (#18160). | |
| 146 | if (e.key === "r") { | |
| 147 | const user = f.user; | |
| 148 | if (isStandInEmail(user.email)) { | |
| 149 | ctx.toast(NO_EMAIL_TO_REMOVE, "danger"); | |
| 150 | return true; | |
| 151 | } | |
| 152 | // The address typed back, as the web's confirm page asks (`/-/confirm`). | |
| 153 | ctx.push( | |
| 154 | promptScreen(ctx, screen, { | |
| 155 | title: "Remove email", | |
| 156 | label: `Remove ${user.email} from your identities? Add one again with e; it starts unproven. Type ${user.email}:`, | |
| 157 | placeholder: user.email, | |
| 158 | onSubmit: (typed) => { | |
| 159 | if (typed !== user.email) return typeBackEmail(user.email); | |
| 160 | const gone = removeEmail(f.app.db, user.id); | |
| 161 | f.user = getUserById(f.app.db, user.id) ?? user; | |
| 162 | ctx.toast(gone ? REMOVED_EMAIL : NO_EMAIL_TO_REMOVE, gone ? "success" : "danger"); | |
| 163 | ctx.invalidate(); | |
| 164 | return undefined; | |
| 165 | }, | |
| 166 | }), | |
| 167 | ); | |
| 168 | return true; | |
| 169 | } | |
| 170 | if (e.key === "l") { | |
| 171 | const code = newLinkCode(f.app, f.user); | |
| 172 | ctx.push( | |
| 173 | confirmScreen(ctx, screen, { | |
| 174 | title: "Link your Minecraft name", | |
| 175 | body: code === undefined ? [NO_LINK_HERE] : [`In game, on any server of the box, type: !forge link ${code} (within 10 minutes, once).`], | |
| 176 | actions: [{ label: "Close" }], | |
| 177 | onChoose: () => ctx.invalidate(), | |
| 178 | }), | |
| 179 | ); | |
| 180 | return true; | |
| 181 | } | |
| 182 | if (e.key === "u") { | |
| 183 | const user = f.user; | |
| 184 | ctx.push( | |
| 185 | promptScreen(ctx, screen, { | |
| 186 | title: "Unlink a Minecraft name", | |
| 187 | label: "player name", | |
| 188 | onSubmit: (v) => { | |
| 189 | const link = accountLinks(f.app, user)?.find((l) => l.player === v.trim()); | |
| 190 | if (link === undefined) { | |
| 191 | ctx.toast(`${v.trim()} is not linked to you.`, "danger"); | |
| 192 | return `${v.trim()} is not linked to you.`; | |
| 193 | } | |
| 194 | unlink(f.app, user.id, link.boxId, link.player); | |
| 195 | ctx.toast(`Unlinked ${link.player}.`, "success"); | |
| 196 | ctx.invalidate(); | |
| 197 | return undefined; | |
| 198 | }, | |
| 199 | }), | |
| 200 | ); | |
| 201 | return true; | |
| 202 | } | |
| 136 | 203 | if (e.key === "x") { |
| 137 | 204 | ctx.push(confirmScreen(ctx, screen, { title: "Your data", body: exportHow(f.app, f.user), actions: [{ label: "Close" }], onChoose: () => ctx.invalidate(), width: 76 })); |
| 138 | 205 | return true; |
src/web/pages/account.ts +2 −2
| @@ -39,7 +39,7 @@ import { linkEdgeLogin, linkedLogin, unlinkEdgeLogin } from "../../core/edge_lin | ||
| 39 | 39 | import { LAST_WAY_IN, linkedParent, parentIssuerOf, unlinkParent } from "../../core/federation.ts"; |
| 40 | 40 | import { activeEdgeToken, edgeIdentity } from "../../http/edge.ts"; |
| 41 | 41 | import { listKeys } from "../../core/keys.ts"; |
| 42 | import { minecraftBlock } from "./games.ts"; | |
| 42 | import { identitiesBlock } from "./proven_identities.ts"; | |
| 43 | 43 | import { listTokensWithClients } from "../../core/oauth.ts"; |
| 44 | 44 | import { |
| 45 | 45 | PROFILE_FALLBACK, |
| @@ -492,7 +492,7 @@ function profileView(ctx: Ctx, values: ProfileForm): Html { | ||
| 492 | 492 | </div> |
| 493 | 493 | ${refusal(values.refused?.errors.form)} |
| 494 | 494 | </form>`, |
| 495 | )}${minecraftBlock(ctx)}`; | |
| 495 | )}${identitiesBlock(ctx)}`; | |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** A reading the cell may not give: a dash, never a zero that says "idle". */ |
src/web/pages/games.ts +1 −26
| @@ -77,7 +77,7 @@ import { LOG_GONE, logReader, LOG_READER_CSS, logReaderJs, logRows, logViewOf, p | ||
| 77 | 77 | import { flashTo, page } from "../layout.ts"; |
| 78 | 78 | import { avatar, badge, btn, disclosure, field as input, row, rowList, time } from "../ui.ts"; |
| 79 | 79 | import { watchBox } from "../../games/notify.ts"; |
| 80 | import { accountLinks, chatLog, newLinkCode, NO_LINK_HERE, playersOn, typedAs, unlink } from "../../games/chat.ts"; | |
| 80 | import { chatLog, newLinkCode, NO_LINK_HERE, playersOn, typedAs, unlink } from "../../games/chat.ts"; | |
| 81 | 81 | import { commitServer, planRemoveServer, planServer, wishOn } from "../../games/presets.ts"; |
| 82 | 82 | import { commitJar, heldWords, leftWords, ONLY_PINNED, pinOf, PINS, planJar } from "../../games/proxy_jars.ts"; |
| 83 | 83 | import { canSleep, commitPolicy, EMPTY_SECONDS, isGameServer, policyOf, proxyOf, proxyPort, STILL_BILLED } from "../../games/sleep.ts"; |
| @@ -208,31 +208,6 @@ export function gamesPage(ctx: Ctx): Response { | ||
| 208 | 208 | })); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | /** | |
| 212 | * The account page's Minecraft block (#17284): the person's linked names with Unlink, and a code to | |
| 213 | * link another. Shown to everyone signed in where the forge has a game box: a link gives no role. | |
| 214 | */ | |
| 215 | export function minecraftBlock(ctx: Ctx): Html | null { | |
| 216 | const links = accountLinks(ctx.app, ctx.auth.user!); | |
| 217 | if (links === undefined) return null; | |
| 218 | return html`<section class="settings-block" data-from-game> | |
| 219 | <h2>Minecraft</h2> | |
| 220 | <p class="muted small">Link your Minecraft name, then type <span class="mono">!forge give me a new void world with FAWE and bedwars</span> in chat on a server you operate: the plan comes back in game, and <span class="mono">!forge yes</span> builds it. Anything else goes to the crew, and their answer comes back in game.</p> | |
| 221 | ${links.length === 0 | |
| 222 | ? null | |
| 223 | : rowList( | |
| 224 | links.map((l) => | |
| 225 | row({ | |
| 226 | title: l.player, | |
| 227 | meta: html`on ${l.box ?? "a box"} · linked ${time(l.createdAt)}${l.uuid === "" ? " · bound to no UUID: link it again" : html` · <span class="mono">${l.uuid}</span>`}`, | |
| 228 | after: html`<form method="post" action="/settings/minecraft/unlink" class="row-fields"><input type="hidden" name="box" value="${l.boxId}" /><input type="hidden" name="player" value="${l.player}" />${btn("Unlink", { variant: "secondary", size: "sm" })}</form>`, | |
| 229 | }), | |
| 230 | ), | |
| 231 | )} | |
| 232 | <form method="post" action="/settings/minecraft/code" class="row-fields">${btn("Link your Minecraft name", { variant: "secondary" })}</form> | |
| 233 | </section>`; | |
| 234 | } | |
| 235 | ||
| 236 | 211 | // POST /settings/minecraft/code: a one-time code (ten minutes) the person types in game as !forge |
| 237 | 212 | // link <code>. |
| 238 | 213 | export async function gameLinkCode(ctx: Ctx): Promise<Response> { |
src/web/pages/proven_identities.ts added +66
| @@ -0,0 +1,66 @@ | ||
| 1 | /** | |
| 2 | * The account page's Identities block (#18160): who you are, in one list read from | |
| 3 | * `core/proven_identities.ts`, each identity proven or unproven. The email is proven by the link | |
| 4 | * mailed to it (`/settings/email/verify` sends another) and removed (`/settings/email/remove`); a | |
| 5 | * Minecraft name by a code typed in game (#17284), shown where the forge has a game box, and | |
| 6 | * unlinked here. The terminal says the same in Your profile (`tui/screens/profile.ts`). | |
| 7 | */ | |
| 8 | import { listOf, NO_EMAIL_TO_REMOVE, REMOVED_EMAIL, removeEmail, typeBackEmail, type Identity } from "../../core/proven_identities.ts"; | |
| 9 | import { isStandInEmail } from "../../core/users.ts"; | |
| 10 | import type { Ctx } from "../../http/context.ts"; | |
| 11 | import { signInFirst } from "../chrome.ts"; | |
| 12 | import { field, readForm } from "../form.ts"; | |
| 13 | import { flashTo } from "../layout.ts"; | |
| 14 | import { html, type Html } from "../html.ts"; | |
| 15 | import { btn, row, rowList, time } from "../ui.ts"; | |
| 16 | ||
| 17 | const emailRow = (i: Identity): Html => | |
| 18 | row({ | |
| 19 | title: i.name, | |
| 20 | // Said once, in the meta: no badge repeating it. Remove is a quiet link: the confirm page it | |
| 21 | // opens carries the danger, so the settings page keeps its one colour (attention budget). | |
| 22 | meta: i.proven ? html`proven${i.since === null ? null : html` ${time(i.since)}`}` : html`unproven: follow the link mailed to it`, | |
| 23 | after: html`${i.proven ? null : html`<form method="post" action="/settings/email/verify" class="row-fields">${btn("Send another link", { variant: "secondary", size: "sm" })}</form>`}${btn("Remove", { href: `/-/confirm?to=${encodeURIComponent("/settings/email/remove")}`, variant: "secondary", size: "sm", label: `Remove ${i.name}` })}`, | |
| 24 | }); | |
| 25 | ||
| 26 | const minecraftRow = (i: Identity): Html => | |
| 27 | row({ | |
| 28 | title: i.name, | |
| 29 | meta: html`Minecraft on ${i.box ?? "a box"} · linked ${time(i.since ?? "")}${i.proven ? html` · proven <span class="mono">${i.uuid}</span>` : " · unproven, bound to no UUID: link it again"}`, | |
| 30 | after: html`<form method="post" action="/settings/minecraft/unlink" class="row-fields"><input type="hidden" name="box" value="${i.boxId ?? ""}" /><input type="hidden" name="player" value="${i.name}" />${btn("Unlink", { variant: "secondary", size: "sm" })}</form>`, | |
| 31 | }); | |
| 32 | ||
| 33 | export function identitiesBlock(ctx: Ctx): Html { | |
| 34 | const user = ctx.auth.user!; | |
| 35 | // One statement: the list and whether a game box exists (the page's statement budget). | |
| 36 | const { identities: all, gameBox } = listOf(ctx.app.db, user.id); | |
| 37 | const emails = all.filter((i) => i.kind === "email" && !isStandInEmail(i.name)); | |
| 38 | const names = all.filter((i) => i.kind === "minecraft"); | |
| 39 | // A Minecraft name is offered only where one can be linked: a game box, or a name already linked. | |
| 40 | const linkable = names.length > 0 || gameBox; | |
| 41 | return html`<section class="settings-block" data-identities> | |
| 42 | <h2>Identities</h2> | |
| 43 | ${emails.length === 0 ? html`<p class="muted small">Add an email in the profile above; it starts unproven.</p>` : rowList(emails.map(emailRow))} | |
| 44 | ${linkable | |
| 45 | ? html`<div data-from-game> | |
| 46 | <p class="muted small">Link your Minecraft name, then type <span class="mono">!forge give me a new void world with FAWE and bedwars</span> in chat on a server you operate: the plan comes back in game, and <span class="mono">!forge yes</span> builds it. Anything else goes to the crew, and their answer comes back in game.</p> | |
| 47 | ${names.length === 0 ? null : rowList(names.map(minecraftRow))} | |
| 48 | <form method="post" action="/settings/minecraft/code" class="row-fields">${btn("Link your Minecraft name", { variant: "secondary" })}</form> | |
| 49 | </div>` | |
| 50 | : null} | |
| 51 | </section>`; | |
| 52 | } | |
| 53 | ||
| 54 | // POST /settings/email/remove: take the email off the account's list; the profile's field adds one | |
| 55 | // again. Only from the confirm page (`/-/confirm`), with the address typed back: the terminal asks | |
| 56 | // first too. | |
| 57 | export async function emailRemove(ctx: Ctx): Promise<Response> { | |
| 58 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 59 | const form = await readForm(ctx, "rw"); | |
| 60 | if (form instanceof Response) return form; | |
| 61 | if (field(form, "confirm") !== ctx.auth.user.email) | |
| 62 | return flashTo(ctx, "/settings", { tone: "danger", message: typeBackEmail(ctx.auth.user.email) }); | |
| 63 | return removeEmail(ctx.app.db, ctx.auth.user.id) | |
| 64 | ? flashTo(ctx, "/settings", { message: REMOVED_EMAIL }) | |
| 65 | : flashTo(ctx, "/settings", { tone: "danger", message: NO_EMAIL_TO_REMOVE }); | |
| 66 | } |
src/web/pages/search.ts +12
| @@ -785,6 +785,18 @@ const DESTRUCTIVE: { | ||
| 785 | 785 | phrase: "", |
| 786 | 786 | }), |
| 787 | 787 | }, |
| 788 | { | |
| 789 | // Remove on Settings › Identities (#18160): the address, typed back | |
| 790 | // (`pages/proven_identities.ts`). | |
| 791 | pattern: /^\/settings\/email\/remove$/, | |
| 792 | describe: (_m, ctx) => ({ | |
| 793 | verb: "Remove", | |
| 794 | title: "Remove your email?", | |
| 795 | detail: | |
| 796 | "The address leaves your identities and its proof is cleared: mail from this forge stops reaching it. Add one again in the profile; it starts unproven.", | |
| 797 | phrase: ctx.auth.user?.email ?? "remove", | |
| 798 | }), | |
| 799 | }, | |
| 788 | 800 | { |
| 789 | 801 | pattern: /^\/settings\/parent\/unlink$/, |
| 790 | 802 | describe: () => ({ |
test/keymap-terminal.test.ts +1
| @@ -49,6 +49,7 @@ const OWN_R: Record<string, string> = { | ||
| 49 | 49 | "src/tui/screens/orgteams.ts": "role", |
| 50 | 50 | "src/tui/screens/outsideagents.ts": "open or close reports", |
| 51 | 51 | "src/tui/screens/people.ts": "change a role", |
| 52 | "src/tui/screens/profile.ts": "remove the email from your identities", | |
| 52 | 53 | "src/tui/screens/pinned.ts": "roll back", |
| 53 | 54 | "src/tui/screens/quarantine.ts": "run the review", |
| 54 | 55 | "src/tui/screens/queuegrowth.ts": "resume past the ceiling", |
test/proven-identities.test.ts added +208
| @@ -0,0 +1,208 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp, type App } from "../src/app.ts"; | |
| 6 | import { identitiesOf, identityLine, minecraftOwner, removeEmail } from "../src/core/proven_identities.ts"; | |
| 7 | import { profileScreen } from "../src/tui/screens/profile.ts"; | |
| 8 | import type { Screen } from "../src/tui/app/app.ts"; | |
| 9 | import { quietCtx, screenText, sessionFor } from "./helpers/tui-text.ts"; | |
| 10 | import { createSession } from "../src/core/sessions.ts"; | |
| 11 | import { createUser, type User } from "../src/core/users.ts"; | |
| 12 | import { consumeLink, emailVerified, issueLink, markUnproven, resetVerification } from "../src/core/verify.ts"; | |
| 13 | import { accountLinks, linksOf, newLinkCode, unlink } from "../src/games/chat.ts"; | |
| 14 | import { createGameBox } from "../src/games/store.ts"; | |
| 15 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; | |
| 16 | ||
| 17 | // One list of who someone is (#18160): the email and the Minecraft names, each proven or not, and | |
| 18 | // the old reads (emailVerified, linksOf, accountLinks, the in-game owner) answer from it. | |
| 19 | describe("identities", () => { | |
| 20 | let dir: string; | |
| 21 | let app: App; | |
| 22 | let http: ForgeHttp; | |
| 23 | let ada: User; | |
| 24 | let boxId: string; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dir = await mkdtemp(join(tmpdir(), "forge-identities-")); | |
| 28 | app = createApp({ dataDir: dir, port: 0, url: "http://forge.test" }); | |
| 29 | http = forgeHttp(app); | |
| 30 | const made = await createUser(app.db, { origin: "edge", username: "ada", email: "[email protected]" }); | |
| 31 | if (!made.ok) throw new Error(made.error); | |
| 32 | ada = made.value; | |
| 33 | markUnproven(app.db, ada.id); | |
| 34 | boxId = createGameBox(app.db, { name: "mc" }).id; | |
| 35 | }); | |
| 36 | afterAll(async () => { | |
| 37 | app.close(); | |
| 38 | await rm(dir, { recursive: true, force: true }); | |
| 39 | }); | |
| 40 | ||
| 41 | const page = async (): Promise<string> => | |
| 42 | (await http.handle(new Request("http://forge.test/settings", { headers: { cookie: `forge_session=${createSession(app.db, ada.id).token}` } }))).text(); | |
| 43 | ||
| 44 | test("an email is added unproven, proven by its one-time link, and unproven again when replaced", async () => { | |
| 45 | const [email] = identitiesOf(app.db, ada.id); | |
| 46 | expect(email).toMatchObject({ kind: "email", name: "[email protected]", proven: false, since: null }); | |
| 47 | expect(emailVerified(app.db, ada.id)).toBe(false); | |
| 48 | expect(identityLine(email!)).toBe("Email [email protected]: unproven"); | |
| 49 | expect(await page()).toContain("data-identities"); | |
| 50 | ||
| 51 | const now = Date.now(); | |
| 52 | const token = issueLink(app.db, ada.id, "[email protected]", now)!; | |
| 53 | expect(consumeLink(app.db, token, now)).toBe(ada.id); | |
| 54 | expect(consumeLink(app.db, token, now)).toBeUndefined(); | |
| 55 | expect(identitiesOf(app.db, ada.id)[0]).toMatchObject({ kind: "email", proven: true }); | |
| 56 | expect(emailVerified(app.db, ada.id)).toBe(true); | |
| 57 | ||
| 58 | // Removing the proof (a new address) leaves the account unproven, through the same read. | |
| 59 | resetVerification(app.db, ada.id); | |
| 60 | expect(identitiesOf(app.db, ada.id)[0]!.proven).toBe(false); | |
| 61 | expect(emailVerified(app.db, ada.id)).toBe(false); | |
| 62 | }); | |
| 63 | ||
| 64 | test("a Minecraft name is added by a code, listed proven once bound to a UUID, and removed", async () => { | |
| 65 | expect(accountLinks(app, ada)).toEqual([]); | |
| 66 | expect(newLinkCode(app, ada)).toMatch(/^[A-Z0-9]{6}$/); | |
| 67 | // What the in-game `!forge link <code>` writes (its flow is game-chat.test.ts's). | |
| 68 | const at = new Date().toISOString(); | |
| 69 | app.db.query("INSERT INTO game_link (box_id, player, user_id, uuid, created_at) VALUES (?1, 'adacraft', ?2, 'u-1', ?3)").run(boxId, ada.id, at); | |
| 70 | app.db.query("INSERT INTO game_link (box_id, player, user_id, uuid, created_at) VALUES (?1, 'oldname', ?2, '', ?3)").run(boxId, ada.id, at); | |
| 71 | ||
| 72 | const names = identitiesOf(app.db, ada.id).filter((i) => i.kind === "minecraft"); | |
| 73 | expect(names.map((i) => [i.name, i.proven])).toEqual([ | |
| 74 | ["adacraft", true], | |
| 75 | ["oldname", false], | |
| 76 | ]); | |
| 77 | expect(identityLine(names[0]!)).toBe("Minecraft adacraft: proven on mc"); | |
| 78 | expect(linksOf(app, ada.id).map((l) => l.player)).toEqual(["adacraft", "oldname"]); | |
| 79 | expect(minecraftOwner(app.db, boxId, "adacraft")).toEqual({ userId: ada.id, uuid: "u-1" }); | |
| 80 | const html = await page(); | |
| 81 | const block = html.slice(html.indexOf("data-identities"), html.indexOf("</section>", html.indexOf("data-identities"))); | |
| 82 | expect(block).toContain("adacraft"); | |
| 83 | expect(block).toContain("unproven"); | |
| 84 | expect(block).toContain('action="/settings/minecraft/unlink"'); | |
| 85 | ||
| 86 | unlink(app, ada.id, boxId, "adacraft"); | |
| 87 | unlink(app, ada.id, boxId, "oldname"); | |
| 88 | expect(identitiesOf(app.db, ada.id).map((i) => i.kind)).toEqual(["email"]); | |
| 89 | expect(minecraftOwner(app.db, boxId, "adacraft")).toBeUndefined(); | |
| 90 | }); | |
| 91 | }); | |
| 92 | ||
| 93 | // The list is drawn for everyone, game box or not (#18160): the email row with Send another link | |
| 94 | // while unproven and Remove; no Minecraft part where no name can be linked. | |
| 95 | describe("identities without a game box", () => { | |
| 96 | let dir: string; | |
| 97 | let app: App; | |
| 98 | let http: ForgeHttp; | |
| 99 | let bo: User; | |
| 100 | beforeAll(async () => { | |
| 101 | dir = await mkdtemp(join(tmpdir(), "forge-identities-none-")); | |
| 102 | app = createApp({ dataDir: dir, port: 0, url: "http://forge.test" }); | |
| 103 | http = forgeHttp(app); | |
| 104 | const made = await createUser(app.db, { origin: "edge", username: "bo", email: "[email protected]" }); | |
| 105 | if (!made.ok) throw new Error(made.error); | |
| 106 | bo = made.value; | |
| 107 | markUnproven(app.db, bo.id); | |
| 108 | }); | |
| 109 | afterAll(async () => { | |
| 110 | app.close(); | |
| 111 | await rm(dir, { recursive: true, force: true }); | |
| 112 | }); | |
| 113 | const cookie = (): string => `forge_session=${createSession(app.db, bo.id).token}`; | |
| 114 | const block = async (): Promise<string> => { | |
| 115 | const res = await http.handle(new Request("http://forge.test/settings", { headers: { cookie: cookie() } })); | |
| 116 | expect(res.status).toBe(200); | |
| 117 | const html = await res.text(); | |
| 118 | const at = html.indexOf("data-identities"); | |
| 119 | expect(at).toBeGreaterThan(-1); | |
| 120 | return html.slice(at, html.indexOf("</section>", at)); | |
| 121 | }; | |
| 122 | ||
| 123 | test("/settings draws the email: Send another link only while unproven, Remove always, no Minecraft part", async () => { | |
| 124 | let b = await block(); | |
| 125 | expect(b).toContain("[email protected]"); | |
| 126 | expect(b).toContain('action="/settings/email/verify"'); | |
| 127 | expect(b).toContain('href="/-/confirm?to=%2Fsettings%2Femail%2Fremove"'); | |
| 128 | expect(b).not.toContain('action="/settings/email/remove"'); | |
| 129 | expect(b).not.toContain("data-from-game"); | |
| 130 | const now = Date.now(); | |
| 131 | consumeLink(app.db, issueLink(app.db, bo.id, "[email protected]", now)!, now); | |
| 132 | b = await block(); | |
| 133 | expect(b).toContain("proven"); | |
| 134 | expect(b).not.toContain('action="/settings/email/verify"'); | |
| 135 | expect(b).toContain('href="/-/confirm?to=%2Fsettings%2Femail%2Fremove"'); | |
| 136 | }); | |
| 137 | ||
| 138 | test("GET /api/v1/identities answers the same list and words, and 401 without an identity", async () => { | |
| 139 | const anon = await http.handle(new Request("http://forge.test/api/v1/identities")); | |
| 140 | expect(anon.status).toBe(401); | |
| 141 | const res = await http.handle(new Request("http://forge.test/api/v1/identities", { headers: { cookie: cookie() } })); | |
| 142 | expect(res.status).toBe(200); | |
| 143 | const body = (await res.json()) as { identities: { kind: string; name: string; proven: boolean; since: string | null; line: string }[] }; | |
| 144 | const [email] = identitiesOf(app.db, bo.id); | |
| 145 | expect(body.identities).toEqual([ | |
| 146 | { kind: "email", name: "[email protected]", proven: email!.proven, since: email!.since, line: identityLine(email!) }, | |
| 147 | ]); | |
| 148 | }); | |
| 149 | ||
| 150 | test("the terminal's Your profile prints the same Identities lines and offers r to remove, the address typed back", async () => { | |
| 151 | const pushed: string[] = []; | |
| 152 | let prompt: Screen | undefined; | |
| 153 | const ctx = { ...quietCtx(), setCursor() {}, push: (s: Screen) => void (pushed.push(s.title), (prompt = s)) }; | |
| 154 | const screen = profileScreen(sessionFor(app, bo), ctx); | |
| 155 | const text = screenText(screen, 120, 20); | |
| 156 | expect(text).toContain("Identities"); | |
| 157 | expect(text).toContain(identityLine(identitiesOf(app.db, bo.id)[0]!)); | |
| 158 | expect(screen.key!({ type: "key", key: "r", ctrl: false, alt: false, shift: false })).toBe(true); | |
| 159 | expect(pushed).toEqual(["Remove email"]); | |
| 160 | for (const key of [..."bo", "enter"]) await prompt!.key!({ type: "key", key, ctrl: false, alt: false, shift: false }); | |
| 161 | expect(screenText(prompt!, 120, 20)).toContain("exactly to confirm"); | |
| 162 | expect(identitiesOf(app.db, bo.id)[0]!.name).toBe("[email protected]"); | |
| 163 | }); | |
| 164 | ||
| 165 | test("Remove asks first: the confirm page wants the address typed back, and the POST refuses without it", async () => { | |
| 166 | const ask = await http.handle(new Request("http://forge.test/-/confirm?to=%2Fsettings%2Femail%2Fremove", { headers: { cookie: cookie() } })); | |
| 167 | expect(ask.status).toBe(200); | |
| 168 | const page = await ask.text(); | |
| 169 | expect(page).toContain('action="/settings/email/remove"'); | |
| 170 | expect(page).toContain("Type [email protected] to continue"); | |
| 171 | expect(page).toContain('data-variant="danger"'); | |
| 172 | }); | |
| 173 | ||
| 174 | test("POST /settings/email/remove takes the email off the list, unproven, once; a cross-origin post is refused", async () => { | |
| 175 | const post = (origin: string, body = "confirm=bo%40outsider.test"): Promise<Response> => | |
| 176 | http.handle( | |
| 177 | new Request("http://forge.test/settings/email/remove", { | |
| 178 | method: "POST", | |
| 179 | headers: { cookie: cookie(), origin, "content-type": "application/x-www-form-urlencoded" }, | |
| 180 | body, | |
| 181 | }), | |
| 182 | ); | |
| 183 | expect((await post("https://evil.example")).status).toBe(403); | |
| 184 | expect(identitiesOf(app.db, bo.id)[0]!.name).toBe("[email protected]"); | |
| 185 | expect((await post("http://forge.test", "")).status).toBe(303); | |
| 186 | expect((await post("http://forge.test", "confirm=bo")).status).toBe(303); | |
| 187 | expect(identitiesOf(app.db, bo.id)[0]!.name).toBe("[email protected]"); | |
| 188 | expect((await post("http://forge.test")).status).toBe(303); | |
| 189 | const [email] = identitiesOf(app.db, bo.id); | |
| 190 | expect(email).toMatchObject({ kind: "email", name: "[email protected]", proven: false }); | |
| 191 | expect(emailVerified(app.db, bo.id)).toBe(false); | |
| 192 | expect(removeEmail(app.db, bo.id)).toBe(false); | |
| 193 | expect(await block()).toContain("Add an email in the profile above"); | |
| 194 | }); | |
| 195 | ||
| 196 | test("an agent's or organization's email counts as proven, and cannot be removed", async () => { | |
| 197 | const made = await createUser(app.db, { origin: "edge", username: "helper", email: "[email protected]" }); | |
| 198 | if (!made.ok) throw new Error(made.error); | |
| 199 | markUnproven(app.db, made.value.id); | |
| 200 | expect(identitiesOf(app.db, made.value.id)[0]!.proven).toBe(false); | |
| 201 | app.db.query("UPDATE user SET is_agent = 1 WHERE id = ?1").run(made.value.id); | |
| 202 | expect(identitiesOf(app.db, made.value.id)[0]!.proven).toBe(true); | |
| 203 | expect(emailVerified(app.db, made.value.id)).toBe(true); | |
| 204 | expect(removeEmail(app.db, made.value.id)).toBe(false); | |
| 205 | app.db.query("UPDATE user SET is_agent = 0, kind = 'org' WHERE id = ?1").run(made.value.id); | |
| 206 | expect(identitiesOf(app.db, made.value.id)[0]!.proven).toBe(true); | |
| 207 | }); | |
| 208 | }); |
new above
offline
Remove is a one-click post that destroys the person's real address (it becomes the stand-in), while the terminal confirms first. Add a confirmation step here too (Never: data deleted without a red button and the person typing its name).