Accounts sign-in looks like the church's site; Events sends its logo and colours

- @crosscode/ui: Shell with the church's colour wash, logo (or its initial)
  and name, footer; Card edged in the church's colour; Heading with an
  icon tile. Icons on every sign-in step.
- contracts 1.9.0: churchLookSchema (logo, accent colour) in import.begin;
  church.branding request. Accounts fills (move) or replaces (button) the
  church profile's name, logo and colours.
- Events 3.1.0: src/accounts/look.ts (logo as a full address), sent with a
  move; Settings -> Sign-in "Use this site's logo and colours".
Tests: Accounts 55, contracts 218, Events 774, test:accounts 16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 21:50:02 +02:00
co-authored by Claude Opus 5.5
parent cc18b7b514
commit 70c471666b
20 changed files with 482 additions and 40 deletions
+5
View File
@@ -22,6 +22,11 @@ password links, sign-in failed with a 500, and nobody could get in. Requires Acc
already moved can mend it. `GET /api/v2/settings/sign-in/messaging`, `POST …/messaging/test`,
`POST …/messaging`.
- **"Use this site's logo and colours"** on Settings → Sign-in (`POST /api/v2/settings/sign-in/look`):
the church's sign-in pages get this site's name, logo (made a full address) and colours
(`church.branding`); a move sends them too, filling only what Accounts doesn't have
(`src/accounts/look.ts`).
### Changed
- **The move needs Accounts' email.** Check reports what Accounts can send (and how many people get
+2
View File
@@ -19,6 +19,8 @@ developer log is CHANGELOG.md. A tagged version without a section here shows "No
does, and sets it up for you: it copies this site's email settings (your password stays where it
is), sends a test, and only saves them in Accounts once the test arrived. The same for WhatsApp.
- If your church already moved without it, the same page sets it up now.
- The church's sign-in page now has your logo and colours: they're taken from this site when you
move, and **Use this site's logo and colours** (Settings → Sign-in) updates them any time.
## 3.0.0 — requires accounts 1.1.0
+31
View File
@@ -0,0 +1,31 @@
/**
* This site's look (3.1.0) for the church's Accounts sign-in pages: its name, logo and colours, so
* signing in looks like the church's own site. Sent with a move (filling what Accounts doesn't have
* yet) and by Settings → Sign-in → "Use this site's logo and colours" (replacing it).
*/
import type { ChurchLook } from '@crosscode/contracts';
import { siteUrl } from '../feed/context';
/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */
const { getSetting } = require('../utils/settingsCache') as { getSetting(k: string, f?: string): Promise<string> };
/* eslint-enable @typescript-eslint/no-require-imports */
const hex = (v: string) => (/^#[0-9a-fA-F]{6}$/.test(v) ? v : null);
export async function churchLook(): Promise<ChurchLook> {
const name = (await getSetting('org_name', '')) || (await getSetting('site_name', '')) || null;
const primary = hex(await getSetting('primary_color', '')) || hex(await getSetting('brand_color', ''));
const accent = hex(await getSetting('accent_color', '')) || hex(await getSetting('secondary_color', ''));
// The logo as an address anyone can load: an uploaded one is a path on this site.
const raw = String(await getSetting('logo_url', '')).trim();
let logoUrl: string | null = null;
if (raw) {
try {
const u = new URL(raw, `${(await siteUrl()).replace(/\/+$/, '')}/`);
if (/^https?:$/.test(u.protocol)) logoUrl = u.toString();
} catch {
logoUrl = null;
}
}
return { name: name ? name.slice(0, 200) : null, primaryColour: primary, accentColour: accent, logoUrl };
}
+3 -8
View File
@@ -18,13 +18,13 @@ import { IMPORT_BATCH_MAX, phoneSchema, type ImportPerson, type ImportResult } f
import { siteUrl } from '../feed/context';
import { accounts, accountsLink, AccountsUnavailable } from './client';
import { accountsMessaging } from './messaging';
import { churchLook } from './look';
import { authMode, CLEARED_KEY, getSetting, MODE_KEY, MOVED_AT_KEY, REPORT_KEY, setSetting, UNDO_DAYS } from './mode';
/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */
const prisma = require('../config/db');
const { decrypt } = require('../utils/encryption') as { decrypt(v: string): string };
const { logAdminAction } = require('../utils/adminAudit') as { logAdminAction(entry: object): Promise<void> };
const { getSettingSync } = require('../utils/settingsCache') as { getSettingSync(k: string, f?: string): string };
/* eslint-enable @typescript-eslint/no-require-imports */
export class MoveError extends Error {
@@ -144,11 +144,6 @@ export async function status(): Promise<MoveSummary> {
};
}
function church() {
const name = getSettingSync('org_name', '') || getSettingSync('site_name', '') || null;
const colour = getSettingSync('primary_color', '') || getSettingSync('brand_color', '');
return { name: name ? name.slice(0, 200) : null, primaryColour: /^#[0-9a-fA-F]{6}$/.test(colour) ? colour : null };
}
export type CheckResult = {
accountsVersion: string;
@@ -177,7 +172,7 @@ async function connected() {
/** The dry run: nothing is written, here or in Accounts. */
export async function check(): Promise<CheckResult> {
const auth = await connected();
const begin = await auth.request<{ noticesTaken: boolean; accountsNoticeVersions: number[]; accountsVersion: string }>({ type: 'import.begin', actor: null, check: true, notices: [], church: church() });
const begin = await auth.request<{ noticesTaken: boolean; accountsNoticeVersions: number[]; accountsVersion: string }>({ type: 'import.begin', actor: null, check: true, notices: [], church: await churchLook() });
if (!versionAtLeast(begin.accountsVersion, MIN_ACCOUNTS)) {
throw new MoveError(`The church's Accounts is version ${begin.accountsVersion}; moving sign-in needs 1.1.0 or later. Update Accounts first.`, 'ACCOUNTS_TOO_OLD');
}
@@ -286,7 +281,7 @@ export async function move(opts: { actor: { id: string; role: string; name?: str
try {
const eventsNotices = await notices();
const begin = await auth.request<{ noticesTaken: boolean; accountsVersion: string }>({
type: 'import.begin', actor: opts.actor.id, check: false, notices: opts.keepAccountsNotices ? [] : eventsNotices, church: church(),
type: 'import.begin', actor: opts.actor.id, check: false, notices: opts.keepAccountsNotices ? [] : eventsNotices, church: await churchLook(),
});
begun = true;
if (!versionAtLeast(begin.accountsVersion, MIN_ACCOUNTS)) throw new MoveError(`The church's Accounts is version ${begin.accountsVersion}; moving sign-in needs 1.1.0 or later.`, 'ACCOUNTS_TOO_OLD');
@@ -6,6 +6,7 @@ import { authMode } from '../../accounts/mode';
import { check, move, MoveError, status, undo } from '../../accounts/move';
import { accounts, accountsLink, AccountsUnavailable } from '../../accounts/client';
import { accountsMessaging, eventsMessaging, sendToAccounts } from '../../accounts/messaging';
import { churchLook } from '../../accounts/look';
/* eslint-disable @typescript-eslint/no-require-imports -- CommonJS */
const prisma = require('../../config/db');
@@ -231,6 +232,23 @@ export const signInMessagingSave = defineRoute({
},
});
export const signInLook = defineRoute({
method: 'post',
path: '/settings/sign-in/look',
tag: 'Accounts',
summary: "Use this site's logo and colours on the church's sign-in pages",
description: "Sends this site's name, logo and colours to the church's Accounts, replacing what its sign-in pages had.",
access: 'admin',
response: single(z.object({ name: z.string().nullable(), logoUrl: z.string().nullable(), primaryColour: z.string().nullable(), accentColour: z.string().nullable() })),
async handler({ user, req }) {
const look = await churchLook();
const actor = (await prisma.user.findUnique({ where: { id: user!.id }, select: { accountId: true } }))?.accountId ?? null;
await (await accounts().catch(asApiError)).request({ type: 'church.branding', actor, church: look, overwrite: true }).catch(asApiError);
await logAdminAction({ actorId: user!.id, actorRole: user!.role, action: 'account_changed_in_accounts', targetType: 'setting', targetId: 'accounts_look', metadata: look, ip: getClientIp(req) });
return { data: { name: look.name, logoUrl: look.logoUrl ?? null, primaryColour: look.primaryColour, accentColour: look.accentColour ?? null } };
},
});
// ─── An admin, for someone's account (sign-in through Accounts) ─────────────
const idParams = z.object({ id: z.uuid() });
@@ -103,6 +103,26 @@ export function SignInTab({ active }: { active: boolean }) {
{status.accountsConnected && <AccountsMessaging onReady={setSending} />}
{status.accountsConnected && (
<section className="border rounded-xl p-4 flex flex-wrap items-center gap-3">
<div className="flex-1 min-w-[16rem]">
<h3 className="font-medium">How the sign-in page looks</h3>
<p className="text-sm text-gray-600">The church&apos;s sign-in page uses its name, logo and colours. Moving sign-in copies this site&apos;s when it has none; this replaces them with this site&apos;s now.</p>
</div>
<button type="button" className="px-3 py-2 rounded-lg border text-sm" disabled={!!busy} onClick={async () => {
setBusy("look");
setMsg(null);
try {
await apiV2("post", "/settings/sign-in/look", auth);
setMsg({ ok: true, text: "The sign-in page now uses this site's logo and colours." });
} catch (e) {
setMsg({ ok: false, text: errorMessage(e) || "That didn't work." });
}
setBusy(null);
}}>{busy === "look" ? "Sending…" : "Use this site's logo and colours"}</button>
</section>
)}
{status.mode === "accounts" ? (
<section className="border rounded-xl p-4 space-y-3">
<p className="text-sm"><span className="font-medium">Through Accounts</span>{status.accountsUrl ? <> at <a className="underline" href={status.accountsUrl} target="_blank" rel="noreferrer">{status.accountsUrl.replace(/^https?:\/\//, "")}</a></> : null}{status.movedAt ? `, since ${when(status.movedAt)}` : ""}.</p>
@@ -73675,6 +73675,96 @@
}
}
},
"/settings/sign-in/look": {
"post": {
"tags": [
"Accounts"
],
"summary": "Use this site's logo and colours on the church's sign-in pages",
"description": "Sends this site's name, logo and colours to the church's Accounts, replacing what its sign-in pages had.\n\n**Who:** Admins only.",
"operationId": "postSettingsSign-inLook",
"security": [
{
"bearerAuth": []
}
],
"parameters": [],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"logoUrl": {
"type": [
"string",
"null"
]
},
"primaryColour": {
"type": [
"string",
"null"
]
},
"accentColour": {
"type": [
"string",
"null"
]
}
},
"required": [
"name",
"logoUrl",
"primaryColour",
"accentColour"
],
"additionalProperties": false
}
},
"required": [
"data"
],
"additionalProperties": false
}
}
}
},
"401": {
"description": "Not signed in (UNAUTHENTICATED)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Not allowed for this role (FORBIDDEN)",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
},
"/users/{id}/account/reset-two-factor": {
"post": {
"tags": [
+67
View File
@@ -7654,6 +7654,28 @@ export interface paths {
patch?: never;
trace?: never;
};
"/settings/sign-in/look": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/**
* Use this site's logo and colours on the church's sign-in pages
* @description Sends this site's name, logo and colours to the church's Accounts, replacing what its sign-in pages had.
*
* **Who:** Admins only.
*/
post: operations["postSettingsSign-inLook"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/users/{id}/account/reset-two-factor": {
parameters: {
query?: never;
@@ -40361,6 +40383,51 @@ export interface operations {
};
};
};
"postSettingsSign-inLook": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data: {
name: string | null;
logoUrl: string | null;
primaryColour: string | null;
accentColour: string | null;
};
};
};
};
/** @description Not signed in (UNAUTHENTICATED) */
401: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
/** @description Not allowed for this role (FORBIDDEN) */
403: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["Error"];
};
};
};
};
"postUsersIdAccountReset-two-factor": {
parameters: {
query?: never;