feat(webui): EULA/PRIVACY consent gate — frontend

ConsentPage shown after login, before the forced password change: tabbed
EULA/PRIVACY rendered by an in-house, dependency-free markdown renderer
(React elements only, XSS-safe; single-pass bounded-class inline parser to
avoid ReDoS on large docs). App gate order is login -> consent -> password ->
app; api client gains agreements.get / recordConsent with a 409 stale-version
re-prompt that refetches the new text.
This commit is contained in:
DrSmoothl committed 2026-06-19 02:27:04 +08:00
1 parent 8c7efc34a9
commit 67c99e1e32
5 files changed
+583 -31

No files matched your search

+22
View File
@@ -2,6 +2,7 @@ import type { AccountConnections, BackupBundle, BackupImportResult, DebugActionD
import type { PasswordRule } from '@/components/pages/change-password-page';
import { normalizeOneBotConfig } from '@/lib/onebot-config';
import {
type AgreementsPayload,
ApiError,
type ApiClient,
type ChangePasswordResult,
@@ -47,6 +48,7 @@ class HttpApiClient implements ApiClient {
readonly notifications: ApiClient['notifications'];
readonly systemSettings: ApiClient['systemSettings'];
readonly debug: ApiClient['debug'];
readonly agreements: ApiClient['agreements'];
constructor(opts: CreateApiClientOptions = {}) {
this.tokenStore = opts.tokenStore ?? localStorageTokenStore(DEFAULT_TOKEN_KEY);
@@ -185,6 +187,26 @@ class HttpApiClient implements ApiClient {
channelId,
}),
};
this.agreements = {
get: () => this.getJson<AgreementsPayload>('/api/agreements'),
recordConsent: async (version) => {
// Read the body even on non-2xx so a 409 can surface currentVersion to
// the caller (instead of fetchJson throwing it away as an ApiError).
// A network failure (fetch reject) must resolve to {success:false}, not
// throw, or the consent button hangs on "提交中…" with no error shown.
try {
const res = await this.request('/api/agreements/record-consent', {
method: 'POST',
body: JSON.stringify({ version }),
});
const data = await readJson<{ success?: boolean; message?: string; currentVersion?: string }>(res);
return { success: res.ok && !!data.success, message: data.message, currentVersion: data.currentVersion };
} catch (e) {
return { success: false, message: e instanceof Error ? e.message : '网络错误,请重试' };
}
},
};
}
// ---------- HTTP helpers ----------
+31
View File
@@ -39,6 +39,29 @@ export type LoginResult =
export type ChangePasswordResult = { success: boolean; message?: string };
export interface AgreementDoc {
id: 'eula' | 'privacy';
title: string;
declaredVersion: string;
effectiveDate: string;
text: string;
}
export interface AgreementsPayload {
/** Content-hash version of the current agreement set. */
version: string;
/** Whether the operator must (re-)accept before using the panel. */
consentRequired: boolean;
documents: AgreementDoc[];
}
export type RecordConsentResult = {
success: boolean;
message?: string;
/** On a 409 version-mismatch, the server's current version to re-fetch. */
currentVersion?: string;
};
export type ProcessActionResult = {
process?: HookProcessInfo & { error?: string };
};
@@ -61,6 +84,14 @@ export interface ApiClient {
checkPasswordStrength(password: string): Promise<{ rules: PasswordRule[]; valid: boolean }>;
changePassword(oldPassword: string, newPassword: string): Promise<ChangePasswordResult>;
// ---- EULA / PRIVACY consent (shown after login, before set-password) ----
agreements: {
/** Fetch agreement texts + current version + whether consent is required. */
get(): Promise<AgreementsPayload>;
/** Record acceptance of `version`. success:false (409) carries currentVersion. */
recordConsent(version: string): Promise<RecordConsentResult>;
};
// ---- system ----
qqList(): Promise<QQInfo[]>;
system(): Promise<SystemInfo>;