diff --git a/config.json b/config.json index ed1bca6b..085b8758 100644 --- a/config.json +++ b/config.json @@ -5,12 +5,14 @@ "featuredCommunities": { "openAsDefault": false, "spaces": ["#gamecult:gamecult.org"], - "rooms": [ - "#tuwunel:grin.hu", - "#free-software-movement:matrix.org", - "#gentoo:matrix.org" - ], - "servers": ["activematrixrooms.com", "matrixrooms.info", "matrix.org", "mozilla.org", "unredacted.org"] + "rooms": ["#tuwunel:grin.hu", "#free-software-movement:matrix.org", "#gentoo:matrix.org"], + "servers": [ + "activematrixrooms.com", + "matrixrooms.info", + "matrix.org", + "mozilla.org", + "unredacted.org" + ] }, "hashRouter": { @@ -24,5 +26,10 @@ "dings": { "enabled": false + }, + + "registration": { + "enabled": false, + "url": "" } } diff --git a/src/app/hooks/useClientConfig.ts b/src/app/hooks/useClientConfig.ts index 759e0c59..adc4a64b 100644 --- a/src/app/hooks/useClientConfig.ts +++ b/src/app/hooks/useClientConfig.ts @@ -7,6 +7,11 @@ export type HashRouterConfig = { basename?: string; }; +export type RegistrationConfig = { + enabled?: boolean; + url?: string; +}; + export type ClientConfig = { defaultHomeserver?: number; homeserverList?: string[]; @@ -26,6 +31,10 @@ export type ClientConfig = { // Per-Mind notification earcons (src/app/features/dings). Off unless `enabled: true`. dings?: DingsConfig; + // The sign-up entry on the sign-in page. Off unless `enabled` is true; `url` is the account + // service's own registration page (a value, never a route this client invents). + registration?: RegistrationConfig; + // Dev preview only: the build answers a pretend homeserver in-page (src/preview-demo). previewDemo?: boolean; }; diff --git a/src/app/pages/Router.tsx b/src/app/pages/Router.tsx index c7444942..71ead024 100644 --- a/src/app/pages/Router.tsx +++ b/src/app/pages/Router.tsx @@ -9,7 +9,7 @@ import { } from 'react-router-dom'; import { ClientConfig } from '../hooks/useClientConfig'; -import { AuthLayout, Login, Register, ResetPassword } from './auth'; +import { AuthLayout, Login, Register, ResetPassword, SignedUp } from './auth'; import { DIRECT_PATH, DESK_PATH, @@ -18,6 +18,7 @@ import { LOGIN_PATH, INBOX_PATH, REGISTER_PATH, + SIGNED_UP_PATH, RESET_PASSWORD_PATH, SPACE_PATH, _CREATE_PATH, @@ -105,6 +106,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) > } /> } /> + } /> } /> diff --git a/src/app/pages/auth/RegisterEntry.tsx b/src/app/pages/auth/RegisterEntry.tsx new file mode 100644 index 00000000..d60e19a6 --- /dev/null +++ b/src/app/pages/auth/RegisterEntry.tsx @@ -0,0 +1,22 @@ +import { Box, Text, color } from 'folds'; +import React from 'react'; +import { useClientConfig } from '../../hooks/useClientConfig'; +import { registrationEntry } from './registrationEntry'; + +// Beside Sign in. Nothing renders unless the config switch is on; the consent sentence and its +// version come from trainingNotice.ts, the same ones a room shows. +export function RegisterEntry() { + const config = useClientConfig(); + const entry = registrationEntry(config); + if (!entry) return null; + return ( + + + Do not have an account? Register + + + {entry.notice} (notice version {entry.noticeVersion}) + + + ); +} diff --git a/src/app/pages/auth/SignedUp.tsx b/src/app/pages/auth/SignedUp.tsx new file mode 100644 index 00000000..70ceff06 --- /dev/null +++ b/src/app/pages/auth/SignedUp.tsx @@ -0,0 +1,24 @@ +import { Box, Text } from 'folds'; +import React from 'react'; +import { Link, Navigate } from 'react-router-dom'; +import { useClientConfig } from '../../hooks/useClientConfig'; +import { getLoginPath } from '../pathUtils'; +import { registrationEntry } from './registrationEntry'; + +// Where the account service sends a newcomer back. It promises nothing about mail or timing: +// the sign-up page said what happens next, and this page points back to it. +export function SignedUp() { + const config = useClientConfig(); + if (!registrationEntry(config)) return ; + return ( + + + You signed up + + Follow the steps from the sign-up page to finish. Then sign in here. + + Sign in + + + ); +} diff --git a/src/app/pages/auth/index.ts b/src/app/pages/auth/index.ts index c4bd0476..78910d5f 100644 --- a/src/app/pages/auth/index.ts +++ b/src/app/pages/auth/index.ts @@ -1,4 +1,5 @@ export * from './AuthLayout'; export * from './login'; export * from './register'; +export * from './SignedUp'; export * from './reset-password'; diff --git a/src/app/pages/auth/login/Login.tsx b/src/app/pages/auth/login/Login.tsx index bc3136f4..ea08e4f0 100644 --- a/src/app/pages/auth/login/Login.tsx +++ b/src/app/pages/auth/login/Login.tsx @@ -9,6 +9,8 @@ import { PasswordLoginForm } from './PasswordLoginForm'; import { SSOLogin } from '../SSOLogin'; import { TokenLogin } from './TokenLogin'; import { OrDivider } from '../OrDivider'; +import { RegisterEntry } from '../RegisterEntry'; +import { registrationEntry } from '../registrationEntry'; import { getLoginPath, getRegisterPath, withSearchParam } from '../../pathUtils'; import { usePathWithOrigin } from '../../../hooks/usePathWithOrigin'; import { LoginPathSearchParams } from '../../paths'; @@ -37,7 +39,8 @@ const useLoginSearchParams = (searchParams: URLSearchParams): LoginPathSearchPar export function Login() { const server = useAuthServer(); - const { hashRouter, previewDemo } = useClientConfig(); + const config = useClientConfig(); + const { hashRouter, previewDemo } = config; const { loginFlows } = useAuthFlows(); const [searchParams] = useSearchParams(); const loginSearchParams = useLoginSearchParams(searchParams); @@ -90,9 +93,13 @@ export function Login() { )} - - Do not have an account? Register - + {registrationEntry(config) ? ( + + ) : ( + + Do not have an account? Register + + )} ); } diff --git a/src/app/pages/auth/registrationEntry.test.ts b/src/app/pages/auth/registrationEntry.test.ts new file mode 100644 index 00000000..3af32faa --- /dev/null +++ b/src/app/pages/auth/registrationEntry.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from 'vitest'; +import { registrationEntry } from './registrationEntry'; +import { + PREVIEW_NOTICE_TEXT, + TRAINING_NOTICE_TEXT, + TRAINING_NOTICE_VERSION, +} from '../../utils/trainingNotice'; +import config from '../../../../config.json'; + +const url = 'https://accounts.example/register'; + +describe('registration entry', () => { + it('is hidden when the switch is absent or off', () => { + expect(registrationEntry({})).toBeUndefined(); + expect(registrationEntry({ registration: { url } })).toBeUndefined(); + expect(registrationEntry({ registration: { enabled: false, url } })).toBeUndefined(); + }); + + it('ships off in config.json', () => { + expect(registrationEntry(config)).toBeUndefined(); + expect(config.registration.enabled).toBe(false); + }); + + it('is hidden when the switch is on but the url is no web address', () => { + expect(registrationEntry({ registration: { enabled: true } })).toBeUndefined(); + expect(registrationEntry({ registration: { enabled: true, url: '' } })).toBeUndefined(); + expect( + registrationEntry({ registration: { enabled: true, url: '/register' } }) + ).toBeUndefined(); + expect( + registrationEntry({ registration: { enabled: true, url: 'data:text/html,x' } }) + ).toBeUndefined(); + }); + + it('reads the consent text and version from trainingNotice.ts', () => { + expect(registrationEntry({ registration: { enabled: true, url } })).toEqual({ + url, + notice: TRAINING_NOTICE_TEXT, + noticeVersion: TRAINING_NOTICE_VERSION, + }); + }); + + it('says the pretend sentence on the pretend server', () => { + const entry = registrationEntry({ previewDemo: true, registration: { enabled: true, url } }); + expect(entry?.notice).toBe(PREVIEW_NOTICE_TEXT); + }); +}); diff --git a/src/app/pages/auth/registrationEntry.ts b/src/app/pages/auth/registrationEntry.ts new file mode 100644 index 00000000..3049403e --- /dev/null +++ b/src/app/pages/auth/registrationEntry.ts @@ -0,0 +1,25 @@ +import type { ClientConfig } from '../../hooks/useClientConfig'; +import { TRAINING_NOTICE_VERSION, trainingNoticeText } from '../../utils/trainingNotice'; + +export type RegistrationEntry = { url: string; notice: string; noticeVersion: number }; + +/** + * The sign-up entry the sign-in page may show: the account service's registration page, when the + * switch is on and the configured url is a plain http(s) address. Anything else is no entry. The + * consent sentence and its version are trainingNotice.ts's, the ones a room shows. + */ +export const registrationEntry = (config: ClientConfig): RegistrationEntry | undefined => { + const { enabled, url } = config.registration ?? {}; + if (enabled !== true || typeof url !== 'string') return undefined; + try { + const { protocol } = new URL(url); + if (protocol !== 'https:' && protocol !== 'http:') return undefined; + } catch { + return undefined; + } + return { + url, + notice: trainingNoticeText(config.previewDemo), + noticeVersion: TRAINING_NOTICE_VERSION, + }; +}; diff --git a/src/app/pages/pathUtils.ts b/src/app/pages/pathUtils.ts index 2738c4c9..d5d81e56 100644 --- a/src/app/pages/pathUtils.ts +++ b/src/app/pages/pathUtils.ts @@ -16,6 +16,7 @@ import { INBOX_NOTIFICATIONS_PATH, INBOX_PATH, REGISTER_PATH, + SIGNED_UP_PATH, RESET_PASSWORD_PATH, ROOT_PATH, SPACE_LOBBY_PATH, @@ -83,6 +84,8 @@ export const getRegisterPath = (server?: string): string => { return generatePath(REGISTER_PATH, params); }; +export const getSignedUpPath = (): string => SIGNED_UP_PATH; + export const getResetPasswordPath = (server?: string): string => { const params = server ? { server: encodeURIComponent(server) } : undefined; return generatePath(RESET_PASSWORD_PATH, params); diff --git a/src/app/pages/paths.ts b/src/app/pages/paths.ts index 6894b477..eba4394d 100644 --- a/src/app/pages/paths.ts +++ b/src/app/pages/paths.ts @@ -17,6 +17,8 @@ export const REGISTER_PATH = '/register/:server?/'; export type ResetPasswordPathSearchParams = { email?: string; }; +export const SIGNED_UP_PATH = '/signed-up/'; + export const RESET_PASSWORD_PATH = '/reset-password/:server?/'; export const _CREATE_PATH = 'create/'; diff --git a/src/app/utils/trainingNotice.ts b/src/app/utils/trainingNotice.ts index c3d6e42a..7d7f6fa1 100644 --- a/src/app/utils/trainingNotice.ts +++ b/src/app/utils/trainingNotice.ts @@ -28,6 +28,13 @@ export const trainingNoticeText = (previewDemo?: boolean): string => * else is malformed. Absent or malformed in any way means no train line. */ export const MAX_NOTICE_VERSION = 4294967295; + +/** + * The version of the notice wording above. Registration shows it with the text, and a room's + * notice event carries the same number, so one text has one version on both surfaces. Bump it + * with the wording and nowhere else. + */ +export const TRAINING_NOTICE_VERSION = 1; export const ROOM_NOTICE_EVENT_TYPE = StateEvent.GameCultNotice; export type RoomNotice = { version: number; scope: 'show' | 'study' | 'train' };