diff --git a/CHANGELOG.md b/CHANGELOG.md index e27081a..49e0d94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ send codes or password links, sign-in failed with a 500, and nobody could get in - **Accounts 1.2.0:** a code or link that can't be sent shows a message instead of a 500 (WhatsApp codes fall back to email); forgot password says email isn't set up; the `messaging.*` requests (test, and save only what worked); a test WhatsApp in its admin; WAWP from the `.env` too. +- **The sign-in pages look like the church's site:** `@crosscode/ui` Shell / Card / Heading redone + (colour wash, logo and name, cards edged in the church's colour, icons); Events sends its logo and + colours (`church.branding`, and with a move). - **Events 3.1.0:** Settings → Sign-in shows what Accounts can send and sets it up by copying this site's SMTP / WAWP (its secrets stay on the server), with a test before saving; the move needs Accounts' email (disabled, and refused by the server, without it). diff --git a/apps/accounts/CHANGELOG.md b/apps/accounts/CHANGELOG.md index f0ca797..acb4acf 100644 --- a/apps/accounts/CHANGELOG.md +++ b/apps/accounts/CHANGELOG.md @@ -16,6 +16,16 @@ sign-in that needed an emailed code failed with a 500, and nobody could get in. - `people.ensure` makes the account even when its "choose your password" email can't go, and tells the product (`emailSent: false`). +### Changed + +- **The sign-in pages look like the church's other sites:** a wash of the church's colour, its logo + and name across the top (its first letter on its colour while there's no logo), the form in a card + edged in that colour with an icon per step, and a footer (`@crosscode/ui` Shell, Card, Heading, + ChurchMark; the account and admin pages get the same frame). +- **The church's logo and colours come from Cross Events:** a move fills the logo, colours and name + Accounts doesn't have yet (`import.begin` now carries the logo and accent colour), and + `church.branding` (contracts 1.9.0) replaces them when an admin asks. + ### Added - **`messaging.*` requests** (contracts 1.9.0) for a linked product's sign-in settings: `status` diff --git a/apps/accounts/WHATS-NEW.md b/apps/accounts/WHATS-NEW.md index 91ffef9..a45972f 100644 --- a/apps/accounts/WHATS-NEW.md +++ b/apps/accounts/WHATS-NEW.md @@ -10,6 +10,7 @@ WHATS-NEW.md; a section shows once its version is tagged). - Email and WhatsApp for sign-in can be set up from Cross Events (Settings → Sign-in), copying its own settings, with a test before they're saved. - Admins can send a test WhatsApp message from Email and WhatsApp. +- **A nicer sign-in page** with your church's logo and colours, taken from Cross Events. ## 1.1.0 diff --git a/apps/accounts/backend/src/links/requests.ts b/apps/accounts/backend/src/links/requests.ts index 13b774b..6e9cf43 100644 --- a/apps/accounts/backend/src/links/requests.ts +++ b/apps/accounts/backend/src/links/requests.ts @@ -16,7 +16,7 @@ import express, { type Request, type Response } from 'express'; import type Provider from 'oidc-provider'; import { ACCOUNTS_REQUEST_PATH, IDENTITY_REQUEST_SCHEMA, identityRequestSchema, - type IdentityRequest, type ImportPerson, type ImportResult, + type ChurchLook, type IdentityRequest, type ImportPerson, type ImportResult, } from '@crosscode/contracts'; import { LINK_HEADERS, openLinkValue, verify } from '@crosscode/contracts/signing'; import type { Ctx } from '../context.js'; @@ -166,13 +166,7 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s await ctx.db.privacyNotice.create({ data: { version: n.version, title: n.title, body: n.body, publishedAt: new Date(n.publishedAt), publishedById: null } }); } } - const stored = await ctx.settings.json & { branding?: { colours?: { primary?: string; accent?: string } } }>('church_profile', {}); - const next = { ...stored }; - if (!stored.name && r.church.name) next.name = r.church.name; - if (!stored.branding?.colours?.primary && r.church.primaryColour) { - next.branding = { logoUrl: null, iconUrl: null, ...(stored.branding ?? {}), colours: { accent: '#f2a900', ...(stored.branding?.colours ?? {}), primary: r.church.primaryColour } } as never; - } - if (JSON.stringify(next) !== JSON.stringify(stored)) await ctx.settings.set('church_profile', JSON.stringify(next)); + await applyLook(ctx, r.church, false); await ctx.db.productLink.update({ where: { installId: link.installId }, data: { importStartedAt: ctx.now() } }); await logRequest(ctx, link, r, 'import_started', null, req, { notices: noticesTaken ? r.notices.length : 0 }); } @@ -290,6 +284,11 @@ async function handle(ctx: Ctx, provider: Provider, link: ProductLink, secret: s await logRequest(ctx, link, r, r.active ? 'account_reactivated_by_product' : 'account_deactivated_by_product', a.id, req); return reply({ ok: true as const }); } + case 'church.branding': { + const changed = await applyLook(ctx, r.church, r.overwrite); + await logRequest(ctx, link, r, 'church_look_from_product', null, req, { changed, overwrite: r.overwrite }); + return reply({ ok: true as const }); + } case 'messaging.status': return reply(await messagingStatus(ctx)); case 'messaging.test': @@ -378,6 +377,29 @@ export function requestsRouter(ctx: Ctx, provider: Provider) { return r; } +/** + * The church's look on Accounts' pages from a product's (1.9.0): its name, logo and colours. + * `overwrite: false` (a move) fills only what's empty; `true` (an admin's button) replaces them. + * Returns the fields changed. + */ +async function applyLook(ctx: Ctx, look: ChurchLook, overwrite: boolean): Promise { + type Stored = Record & { name?: string; branding?: { logoUrl?: string | null; iconUrl?: string | null; colours?: { primary?: string; accent?: string | null } } }; + const stored = await ctx.settings.json('church_profile', {}); + const branding = { logoUrl: null as string | null, iconUrl: null as string | null, ...(stored.branding ?? {}), colours: { primary: '#1f4e79', accent: '#f2a900', ...(stored.branding?.colours ?? {}) } }; + const changed: string[] = []; + const take = (has: unknown, value: unknown) => value !== null && value !== undefined && value !== '' && (overwrite || !has); + const next: Stored = { ...stored }; + if (take(stored.name, look.name)) { next.name = look.name!; changed.push('name'); } + if (take(stored.branding?.logoUrl, look.logoUrl)) { branding.logoUrl = look.logoUrl!; changed.push('logo'); } + if (take(stored.branding?.colours?.primary, look.primaryColour)) { branding.colours.primary = look.primaryColour!; changed.push('primary colour'); } + if (take(stored.branding?.colours?.accent && stored.branding?.colours?.accent !== '#f2a900', look.accentColour)) { branding.colours.accent = look.accentColour!; changed.push('accent colour'); } + if (!changed.length) return changed; + next.branding = branding; + next.updatedAt = ctx.now().toISOString(); + await ctx.settings.set('church_profile', JSON.stringify(next)); + return changed; +} + /** What can be sent now (no secrets), for a product's sign-in settings page. */ async function messagingStatus(ctx: Ctx) { const emailReady = await ctx.messenger.emailReady(); diff --git a/apps/accounts/backend/tests/messaging.test.ts b/apps/accounts/backend/tests/messaging.test.ts index 66c0b60..28dc0d5 100644 --- a/apps/accounts/backend/tests/messaging.test.ts +++ b/apps/accounts/backend/tests/messaging.test.ts @@ -105,3 +105,21 @@ describe('messaging.* from a product', () => { assert.equal(r.body.emailSent, false); }); }); + +describe('the church\'s look from a product (1.9.0)', () => { + test('a move fills only what\'s empty; the button replaces it', async () => { + await h.ctx.settings.set('church_profile', JSON.stringify({ name: 'Hope Family Church', shortName: 'Hope' })); + const look = { name: 'Other Name', primaryColour: '#123456', accentColour: '#abcdef', logoUrl: 'https://events.hope.test/uploads/logo.png' }; + assert.equal((await ask({ type: 'church.branding', church: look, overwrite: false })).status, 200); + const filled = await h.ctx.settings.json<{ name: string; branding: { logoUrl: string; colours: { primary: string; accent: string } } }>('church_profile', {} as never); + assert.equal(filled.name, 'Hope Family Church', 'kept'); + assert.equal(filled.branding.logoUrl, 'https://events.hope.test/uploads/logo.png'); + assert.equal(filled.branding.colours.primary, '#123456'); + await ask({ type: 'church.branding', church: { ...look, primaryColour: '#654321', logoUrl: 'https://events.hope.test/new.png' }, overwrite: true }); + const replaced = await h.ctx.settings.json<{ name: string; branding: { logoUrl: string; colours: { primary: string } } }>('church_profile', {} as never); + assert.deepEqual([replaced.name, replaced.branding.logoUrl, replaced.branding.colours.primary], ['Other Name', 'https://events.hope.test/new.png', '#654321']); + // The sign-in pages get it. + const b = await h.api(new Browser(), 'GET', '/api/v2/branding'); + assert.equal(b.body.logoUrl, 'https://events.hope.test/new.png'); + }); +}); diff --git a/apps/accounts/frontend/src/app/forgot/Forgot.tsx b/apps/accounts/frontend/src/app/forgot/Forgot.tsx index 3f78618..f1159e1 100644 --- a/apps/accounts/frontend/src/app/forgot/Forgot.tsx +++ b/apps/accounts/frontend/src/app/forgot/Forgot.tsx @@ -1,5 +1,6 @@ "use client"; +import { KeyRound } from "lucide-react"; import React, { useState } from "react"; import { Button, Card, Field, Heading, Notice, Shell } from "@crosscode/ui"; import { useBranding } from "@/components/BrandingProvider"; @@ -13,7 +14,7 @@ export function Forgot({ uid }: { uid: string | null }) { return ( - Forgot your password? + } sub="We'll email you a link to choose a new one.">Forgot your password? {sent ? ( If there's an account with that email address, a link is on its way. It works for an hour. You can close this page: the link brings you back. ) : ( diff --git a/apps/accounts/frontend/src/app/reset/Reset.tsx b/apps/accounts/frontend/src/app/reset/Reset.tsx index 5a76a4e..3d2ec70 100644 --- a/apps/accounts/frontend/src/app/reset/Reset.tsx +++ b/apps/accounts/frontend/src/app/reset/Reset.tsx @@ -1,5 +1,6 @@ "use client"; +import { KeyRound } from "lucide-react"; import React, { useState } from "react"; import { Button, Card, Field, Heading, Notice, Shell } from "@crosscode/ui"; import { useBranding } from "@/components/BrandingProvider"; @@ -12,7 +13,7 @@ export function Reset({ token }: { token: string | null }) { return ( - Choose a new password + } sub="At least 8 characters.">Choose a new password {error && {error}}
{ e.preventDefault(); diff --git a/apps/accounts/frontend/src/app/signed-out/page.tsx b/apps/accounts/frontend/src/app/signed-out/page.tsx index 46eff86..16ffc4f 100644 --- a/apps/accounts/frontend/src/app/signed-out/page.tsx +++ b/apps/accounts/frontend/src/app/signed-out/page.tsx @@ -1,5 +1,6 @@ "use client"; +import { LogOut } from "lucide-react"; import { Card, Heading, Shell } from "@crosscode/ui"; import { useBranding } from "@/components/BrandingProvider"; import { selfSignIn } from "@/lib/api"; @@ -9,7 +10,7 @@ export default function SignedOutPage() { return ( - You're signed out + } sub={`You've been signed out of all of ${branding.name}'s sites.`}>You're signed out Sign in again diff --git a/apps/accounts/frontend/src/app/signin/SignIn.tsx b/apps/accounts/frontend/src/app/signin/SignIn.tsx index e802860..dcd2b0f 100644 --- a/apps/accounts/frontend/src/app/signin/SignIn.tsx +++ b/apps/accounts/frontend/src/app/signin/SignIn.tsx @@ -1,5 +1,6 @@ "use client"; +import { AlertTriangle, FileText, KeyRound, LogIn, Mail, Megaphone, ShieldCheck, UserPlus } from "lucide-react"; import React, { useState } from "react"; import QRCode from "qrcode"; import { Button, Card, Checkbox, Field, Heading, Notice, Shell } from "@crosscode/ui"; @@ -88,7 +89,7 @@ export function SignIn({ uid }: { uid: string }) { if (!state) { return frame(error ? ( <> - We couldn't continue + }>We couldn't continue {error.message} ) :

Loading…

); @@ -121,7 +122,7 @@ function PasswordStep({ state, busy, err, onSubmit, onSignUp }: { state: State; const branding = useBranding(); return ( { e.preventDefault(); const f = new FormData(e.currentTarget); onSubmit({ email: f.get("email"), password: f.get("password"), remember: f.get("remember") === "on" }); }}> - Sign in to {branding.name} + } sub={`to continue to ${state.product}`}>Sign in to {branding.name} {err} @@ -144,7 +145,7 @@ function SignUpStep({ busy, err, fieldError, onSubmit, onBack }: { busy: boolean const f = new FormData(e.currentTarget); onSubmit({ name: f.get("name"), email: f.get("email"), phone: f.get("phone") || undefined, password: f.get("password"), acceptNotice: f.get("acceptNotice") === "on", newsEmail: f.get("newsEmail") === "on", newsWhatsApp: f.get("newsWhatsApp") === "on", remember: true }); }}> - Create your account + } sub={`One account for all of ${branding.name}'s sites and apps.`}>Create your account {err} @@ -162,7 +163,7 @@ function SignUpStep({ busy, err, fieldError, onSubmit, onBack }: { busy: boolean function CodeStep({ title, sub, busy, err, onSubmit, onResend }: { title: string; sub: React.ReactNode; busy: boolean; err: React.ReactNode; onSubmit: (code: string) => void; onResend?: () => void }) { return ( { e.preventDefault(); onSubmit(String(new FormData(e.currentTarget).get("code") ?? "")); }}> - {title} + } sub={sub}>{title} {err} @@ -212,7 +213,7 @@ function SetupStep({ uid, state, busy, err, setError, onConfirm }: { uid: string }; return ( <> - Set up two-step sign-in + } sub={why}>Set up two-step sign-in {err}
{(state.methods ?? []).map((m) => ( @@ -243,7 +244,7 @@ function RecoveryCodes({ codes, onDone }: { codes: string[]; onDone: () => void const text = codes.join("\n"); return ( <> - Save your recovery codes + } sub="If you lose your phone, one of these lets you sign in. Each works once. Keep them somewhere safe: we can't show them again.">Save your recovery codes
{text}
@@ -257,7 +258,7 @@ function RecoveryCodes({ codes, onDone }: { codes: string[]; onDone: () => void function NoticeStep({ state, busy, err, onAccept }: { state: State; busy: boolean; err: React.ReactNode; onAccept: () => void }) { return ( <> - {state.notice!.title} + } sub={state.updated ? "Our privacy notice has changed. Please read it before you carry on." : "Please read our privacy notice before you carry on."}>{state.notice!.title} {err}
{state.notice!.body}
@@ -269,7 +270,7 @@ function NewsStep({ busy, err, onSubmit }: { busy: boolean; err: React.ReactNode const branding = useBranding(); return ( { e.preventDefault(); const f = new FormData(e.currentTarget); onSubmit({ email: f.get("email") === "on", whatsapp: f.get("whatsapp") === "on" }); }}> - Would you like news from {branding.name}? + } sub="You can change this at any time on your account page.">Would you like news from {branding.name}? {err} diff --git a/apps/events/CHANGELOG.md b/apps/events/CHANGELOG.md index 3f8b71e..eb5e69b 100644 --- a/apps/events/CHANGELOG.md +++ b/apps/events/CHANGELOG.md @@ -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 diff --git a/apps/events/WHATS-NEW.md b/apps/events/WHATS-NEW.md index 4a9f290..0b288c7 100644 --- a/apps/events/WHATS-NEW.md +++ b/apps/events/WHATS-NEW.md @@ -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 diff --git a/apps/events/backend/src/accounts/look.ts b/apps/events/backend/src/accounts/look.ts new file mode 100644 index 0000000..884cff7 --- /dev/null +++ b/apps/events/backend/src/accounts/look.ts @@ -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 }; +/* 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 { + 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 }; +} diff --git a/apps/events/backend/src/accounts/move.ts b/apps/events/backend/src/accounts/move.ts index 6bbd0c2..aa04db7 100644 --- a/apps/events/backend/src/accounts/move.ts +++ b/apps/events/backend/src/accounts/move.ts @@ -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 }; -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 { }; } -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 { 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'); diff --git a/apps/events/backend/src/v2/resources/signIn.ts b/apps/events/backend/src/v2/resources/signIn.ts index cb78aab..5b0ac3e 100644 --- a/apps/events/backend/src/v2/resources/signIn.ts +++ b/apps/events/backend/src/v2/resources/signIn.ts @@ -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() }); diff --git a/apps/events/frontend/src/components/admin/SignInTab.tsx b/apps/events/frontend/src/components/admin/SignInTab.tsx index af120f0..945e0b8 100644 --- a/apps/events/frontend/src/components/admin/SignInTab.tsx +++ b/apps/events/frontend/src/components/admin/SignInTab.tsx @@ -103,6 +103,26 @@ export function SignInTab({ active }: { active: boolean }) { {status.accountsConnected && } + {status.accountsConnected && ( +
+
+

How the sign-in page looks

+

The church's sign-in page uses its name, logo and colours. Moving sign-in copies this site's when it has none; this replaces them with this site's now.

+
+ +
+ )} + {status.mode === "accounts" ? (

Through Accounts{status.accountsUrl ? <> at {status.accountsUrl.replace(/^https?:\/\//, "")} : null}{status.movedAt ? `, since ${when(status.movedAt)}` : ""}.

diff --git a/apps/events/frontend/src/lib/api-v2/openapi.json b/apps/events/frontend/src/lib/api-v2/openapi.json index 21897a0..24b3bd8 100644 --- a/apps/events/frontend/src/lib/api-v2/openapi.json +++ b/apps/events/frontend/src/lib/api-v2/openapi.json @@ -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": [ diff --git a/apps/events/frontend/src/lib/api-v2/schema.d.ts b/apps/events/frontend/src/lib/api-v2/schema.d.ts index 28bb256..7f1ebb2 100644 --- a/apps/events/frontend/src/lib/api-v2/schema.d.ts +++ b/apps/events/frontend/src/lib/api-v2/schema.d.ts @@ -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; diff --git a/packages/contracts/schemas/identity-request.json b/packages/contracts/schemas/identity-request.json index 91b19ad..e11988b 100644 --- a/packages/contracts/schemas/identity-request.json +++ b/packages/contracts/schemas/identity-request.json @@ -93,6 +93,29 @@ "type": "null" } ] + }, + "accentColour": { + "anyOf": [ + { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + { + "type": "null" + } + ] + }, + "logoUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] } }, "required": [ @@ -1096,6 +1119,102 @@ "actor", "type" ] + }, + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity-request/1" + }, + "requestId": { + "type": "string", + "format": "uuid", + "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$" + }, + "actor": { + "anyOf": [ + { + "type": "string", + "format": "uuid", + "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$" + }, + { + "type": "null" + } + ] + }, + "type": { + "type": "string", + "const": "church.branding" + }, + "church": { + "type": "object", + "properties": { + "name": { + "anyOf": [ + { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "primaryColour": { + "anyOf": [ + { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + { + "type": "null" + } + ] + }, + "accentColour": { + "anyOf": [ + { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + { + "type": "null" + } + ] + }, + "logoUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "name", + "primaryColour" + ] + }, + "overwrite": { + "type": "boolean" + } + }, + "required": [ + "schema", + "requestId", + "actor", + "type", + "church", + "overwrite" + ] } ] } diff --git a/packages/contracts/src/identity-request.ts b/packages/contracts/src/identity-request.ts index 18b260d..250b579 100644 --- a/packages/contracts/src/identity-request.ts +++ b/packages/contracts/src/identity-request.ts @@ -43,6 +43,18 @@ const base = z.object({ // ─── import.* ──────────────────────────────────────────────────────────────── +/** + * The church's look as a product has it, for Accounts' sign-in pages: its name, logo (an https + * address) and colours. 1.9.0 adds the logo and accent colour (optional, so 1.8.0 senders still fit). + */ +export const churchLookSchema = z.object({ + name: z.string().trim().min(1).max(200).nullable(), + primaryColour: z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable(), + accentColour: z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable().optional(), + logoUrl: z.url({ protocol: /^https?$/ }).max(2048).nullable().optional(), +}); +export type ChurchLook = z.infer; + /** A privacy notice version, numbers kept (EVENTS-3.0-PLAN decision 5). */ export const importNoticeSchema = z.object({ version: z.int().positive(), @@ -90,7 +102,7 @@ export const importBeginSchema = base.extend({ /** The product's privacy notice versions. Taken only when Accounts has published none of its own. */ notices: z.array(importNoticeSchema).max(100), /** Fills the church profile's empty fields, so the sign-in page looks like the church at once. */ - church: z.object({ name: z.string().trim().min(1).max(200).nullable(), primaryColour: z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable() }), + church: churchLookSchema, }); export const importBatchSchema = base.extend({ @@ -179,10 +191,16 @@ export const messagingTestSchema = base.extend({ /** Tests the settings given as messaging.test does, and saves each part only if its test worked. */ export const messagingSetSchema = messagingTestSchema.extend({ type: z.literal("messaging.set") }); +/** + * 1.9.0: use the product's look (name, logo, colours) on Accounts' pages. `overwrite: false` only + * fills what Accounts doesn't have yet; `true` replaces it (an admin pressing the button). + */ +export const churchBrandingSchema = base.extend({ type: z.literal("church.branding"), church: churchLookSchema, overwrite: z.boolean() }); + export const identityRequestSchema = z.discriminatedUnion("type", [ importBeginSchema, importBatchSchema, importFinishSchema, importAbortSchema, peopleEnsureSchema, peopleUpdateSchema, peopleResetTwoFactorSchema, peopleUnlockSchema, peopleSetActiveSchema, peopleNewsOffSchema, - messagingStatusSchema, messagingTestSchema, messagingSetSchema, + messagingStatusSchema, messagingTestSchema, messagingSetSchema, churchBrandingSchema, ]); export type IdentityRequest = z.infer; export type IdentityRequestType = IdentityRequest["type"]; diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx index 17508af..bd7fc14 100644 --- a/packages/ui/src/index.tsx +++ b/packages/ui/src/index.tsx @@ -9,30 +9,49 @@ const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).jo export type Branding = { name: string; shortName?: string | null; logoUrl?: string | null }; /** The page frame: the church's logo and name, then the content in a centred column. */ +/** The church's logo, or its first letter on its colour while it has none. */ +export function ChurchMark({ branding, size = "md" }: { branding: Branding; size?: "md" | "lg" }) { + const box = size === "lg" ? "h-14 w-14 text-2xl" : "h-10 w-10 text-lg"; + if (branding.logoUrl) return ; + return {(branding.shortName || branding.name || "?").trim().charAt(0).toUpperCase()}; +} + +/** + * The page frame (as the church's other sites): a soft wash of the church's colour, its logo and + * name across the top, the content in a centred column, and a quiet footer. `wide` for the account + * and admin pages; otherwise a sign-in column. + */ export function Shell({ branding, children, wide = false, aside }: { branding: Branding; children: React.ReactNode; wide?: boolean; aside?: React.ReactNode }) { return ( -
-
-
- {branding.logoUrl ? : } - {branding.name} +
+
+
+ + {branding.name} {aside &&
{aside}
}
-
{children}
+
{children}
+
+ {branding.name} · your church account, for all its sites and apps +
); } export function Card({ children, className }: { children: React.ReactNode; className?: string }) { - return
{children}
; + return
{children}
; } -export function Heading({ children, sub }: { children: React.ReactNode; sub?: React.ReactNode }) { +/** A page's title, with an optional icon in a tile of the church's colour (as on the church's other sites). */ +export function Heading({ children, sub, icon }: { children: React.ReactNode; sub?: React.ReactNode; icon?: React.ReactNode }) { return ( -
-

{children}

- {sub &&

{sub}

} +
+ {icon && {icon}} +
+

{children}

+ {sub &&

{sub}

} +
); }