After adding the setting for account locked
This commit is contained in:
parent
5832e1b56f
commit
acb25b0d10
@ -121,6 +121,12 @@ export async function login(req: Request, res: Response): Promise<void> {
|
||||
res.status(status).json({
|
||||
error: clientErrorMessage(e, 'Login failed'),
|
||||
...(code ? { code } : {}),
|
||||
...((e as { lockedUntil?: string }).lockedUntil
|
||||
? { lockedUntil: (e as { lockedUntil: string }).lockedUntil }
|
||||
: {}),
|
||||
...((e as { retryAfterMinutes?: number }).retryAfterMinutes != null
|
||||
? { retryAfterMinutes: (e as { retryAfterMinutes: number }).retryAfterMinutes }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,6 +207,40 @@ export async function listFailedLogins(req: AuthRequest, res: Response): Promise
|
||||
}
|
||||
}
|
||||
|
||||
export async function listLockedAccounts(_req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const loginLockoutService = await import('../services/loginLockoutService');
|
||||
const items = await loginLockoutService.listTemporarilyLockedAccounts();
|
||||
res.json({ items, total: items.length });
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to list locked accounts';
|
||||
res.status(500).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
export async function unlockAccount(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const userId = req.params.userId;
|
||||
if (!userId) {
|
||||
res.status(400).json({ error: 'userId is required' });
|
||||
return;
|
||||
}
|
||||
const loginLockoutService = await import('../services/loginLockoutService');
|
||||
const { reason } = (req.body ?? {}) as { reason?: string };
|
||||
await loginLockoutService.adminUnlockAccount(userId, {
|
||||
adminUserId: req.user!.userId,
|
||||
ipAddress: req.ip || undefined,
|
||||
userAgent: req.get('user-agent') || undefined,
|
||||
reason,
|
||||
});
|
||||
res.json({ ok: true });
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Failed to unlock account';
|
||||
const status = msg === 'User not found' ? 404 : 500;
|
||||
res.status(status).json({ error: msg });
|
||||
}
|
||||
}
|
||||
|
||||
export async function exportAuditLogsCsv(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const filters = req.query as unknown as AuditLogExportQuery;
|
||||
|
||||
@ -175,6 +175,31 @@ export async function getFailedLoginCount(userId: string): Promise<number> {
|
||||
return rows[0]?.failed_login_count ?? 0;
|
||||
}
|
||||
|
||||
export type TemporarilyLockedUserRow = {
|
||||
id: string;
|
||||
email_encrypted: string | null;
|
||||
phone_encrypted: string | null;
|
||||
first_name: string | null;
|
||||
last_name: string | null;
|
||||
failed_login_count: number;
|
||||
login_locked_until: Date;
|
||||
updated_at: Date;
|
||||
};
|
||||
|
||||
/** Users with an active or recently set temporary login lock. */
|
||||
export async function listTemporarilyLockedUsers(): Promise<TemporarilyLockedUserRow[]> {
|
||||
return query<TemporarilyLockedUserRow[]>(
|
||||
`SELECT id, email_encrypted, phone_encrypted, first_name, last_name,
|
||||
failed_login_count, login_locked_until, updated_at
|
||||
FROM users
|
||||
WHERE deleted_at IS NULL
|
||||
AND login_locked_until IS NOT NULL
|
||||
AND login_locked_until > NOW() - INTERVAL '24 hours'
|
||||
ORDER BY login_locked_until DESC
|
||||
LIMIT 500`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a role ID to its display name.
|
||||
* @param roleId - Numeric role identifier.
|
||||
|
||||
@ -383,6 +383,18 @@ router.get(
|
||||
validateQuery(auditLogQuerySchema),
|
||||
securityController.listFailedLogins
|
||||
);
|
||||
router.get(
|
||||
'/admin/security/locked-accounts',
|
||||
requireRoles('admin'),
|
||||
requirePermissions('security.admin'),
|
||||
securityController.listLockedAccounts
|
||||
);
|
||||
router.post(
|
||||
'/admin/security/locked-accounts/:userId/unlock',
|
||||
requireRoles('admin'),
|
||||
requirePermissions('security.admin'),
|
||||
securityController.unlockAccount
|
||||
);
|
||||
router.get(
|
||||
'/admin/security/audit-logs/export.csv',
|
||||
requireRoles('admin'),
|
||||
|
||||
@ -349,6 +349,7 @@ export async function login(
|
||||
userAgent: auditUa,
|
||||
reason: 'invalid_password',
|
||||
});
|
||||
await loginLockoutService.assertLoginNotLocked(user.id);
|
||||
throw new Error('Invalid credentials');
|
||||
}
|
||||
|
||||
@ -370,6 +371,7 @@ export async function login(
|
||||
userAgent: auditUa,
|
||||
reason: 'invalid_2fa',
|
||||
});
|
||||
await loginLockoutService.assertLoginNotLocked(user.id);
|
||||
throw new Error('Invalid 2FA code');
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,17 +4,53 @@
|
||||
|
||||
import * as settingsRepository from '../repositories/settingsRepository';
|
||||
import * as userRepository from '../repositories/userRepository';
|
||||
import { decrypt } from '../utils/crypto';
|
||||
import { logSecurityEvent } from '../utils/securityAudit';
|
||||
|
||||
export type AccountLockedError = Error & {
|
||||
code: 'ACCOUNT_LOCKED';
|
||||
lockedUntil: string;
|
||||
retryAfterMinutes: number;
|
||||
};
|
||||
|
||||
function safeDecrypt(encrypted: string | null | undefined): string | null {
|
||||
if (!encrypted) return null;
|
||||
try {
|
||||
return decrypt(encrypted);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function minutesRemaining(lockedUntil: Date, now = Date.now()): number {
|
||||
return Math.max(1, Math.ceil((lockedUntil.getTime() - now) / 60_000));
|
||||
}
|
||||
|
||||
export function buildAccountLockedError(lockedUntil: Date): AccountLockedError {
|
||||
const retryAfterMinutes = minutesRemaining(lockedUntil);
|
||||
const err = new Error(
|
||||
`Your account has been temporarily locked after several unsuccessful login attempts. You can try again in ${retryAfterMinutes} minute${retryAfterMinutes === 1 ? '' : 's'}.`
|
||||
) as AccountLockedError;
|
||||
err.code = 'ACCOUNT_LOCKED';
|
||||
err.lockedUntil = lockedUntil.toISOString();
|
||||
err.retryAfterMinutes = retryAfterMinutes;
|
||||
return err;
|
||||
}
|
||||
|
||||
export async function assertLoginNotLocked(userId: string): Promise<void> {
|
||||
const lockedUntil = await userRepository.getLoginLockedUntil(userId);
|
||||
if (lockedUntil && lockedUntil.getTime() > Date.now()) {
|
||||
const err = new Error('Account is temporarily locked due to too many failed login attempts') as Error & {
|
||||
code?: string;
|
||||
};
|
||||
err.code = 'ACCOUNT_LOCKED';
|
||||
throw err;
|
||||
if (!lockedUntil) return;
|
||||
|
||||
if (lockedUntil.getTime() > Date.now()) {
|
||||
throw buildAccountLockedError(lockedUntil);
|
||||
}
|
||||
|
||||
// Lock expired: clear state and audit automatic unlock.
|
||||
await userRepository.resetFailedLoginState(userId);
|
||||
logSecurityEvent('login_lockout_expired', {
|
||||
userId,
|
||||
metadata: { lockedUntil: lockedUntil.toISOString(), unlockedAt: new Date().toISOString() },
|
||||
});
|
||||
}
|
||||
|
||||
export async function recordFailedLogin(
|
||||
@ -28,9 +64,22 @@ export async function recordFailedLogin(
|
||||
const count = await userRepository.incrementFailedLoginCount(userId);
|
||||
let lockedUntil: Date | null = null;
|
||||
|
||||
if (count >= maxAttempts && lockoutMinutes > 0) {
|
||||
// maxAttempts <= 0 disables lockout by attempt count; lockoutMinutes <= 0 disables duration.
|
||||
if (maxAttempts > 0 && lockoutMinutes > 0 && count >= maxAttempts) {
|
||||
lockedUntil = new Date(Date.now() + lockoutMinutes * 60 * 1000);
|
||||
await userRepository.setLoginLockedUntil(userId, lockedUntil);
|
||||
logSecurityEvent('login_lockout_triggered', {
|
||||
userId,
|
||||
ipAddress: ctx.ipAddress ?? null,
|
||||
userAgent: ctx.userAgent ?? null,
|
||||
metadata: {
|
||||
reason: ctx.reason,
|
||||
failedCount: count,
|
||||
maxAttempts,
|
||||
lockoutMinutes,
|
||||
lockedUntil: lockedUntil.toISOString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
logSecurityEvent('login_failed', {
|
||||
@ -48,3 +97,73 @@ export async function recordFailedLogin(
|
||||
export async function clearLoginFailures(userId: string): Promise<void> {
|
||||
await userRepository.resetFailedLoginState(userId);
|
||||
}
|
||||
|
||||
export async function adminUnlockAccount(
|
||||
userId: string,
|
||||
ctx: { adminUserId: string; ipAddress?: string; userAgent?: string; reason?: string }
|
||||
): Promise<void> {
|
||||
const existing = await userRepository.findById(userId);
|
||||
if (!existing) {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
const lockedUntil = await userRepository.getLoginLockedUntil(userId);
|
||||
const failedCount = await userRepository.getFailedLoginCount(userId);
|
||||
|
||||
await userRepository.resetFailedLoginState(userId);
|
||||
|
||||
logSecurityEvent('login_lockout_cleared', {
|
||||
userId,
|
||||
ipAddress: ctx.ipAddress ?? null,
|
||||
userAgent: ctx.userAgent ?? null,
|
||||
metadata: {
|
||||
adminUserId: ctx.adminUserId,
|
||||
reason: ctx.reason ?? 'admin_manual_unlock',
|
||||
previousFailedCount: failedCount,
|
||||
previousLockedUntil: lockedUntil?.toISOString() ?? null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export type LockedAccountRow = {
|
||||
id: string;
|
||||
email: string | null;
|
||||
fullName: string | null;
|
||||
phone: string | null;
|
||||
failedLoginCount: number;
|
||||
lockedUntil: string;
|
||||
lockedAtApprox: string | null;
|
||||
remainingMinutes: number;
|
||||
status: 'locked' | 'expired';
|
||||
};
|
||||
|
||||
export async function listTemporarilyLockedAccounts(): Promise<LockedAccountRow[]> {
|
||||
const settings = await settingsRepository.getSettings();
|
||||
const lockoutMinutes = settings.login_lockout_minutes;
|
||||
const rows = await userRepository.listTemporarilyLockedUsers();
|
||||
const now = Date.now();
|
||||
|
||||
return rows.map((row) => {
|
||||
const lockedUntil = new Date(row.login_locked_until);
|
||||
const remaining = lockedUntil.getTime() - now;
|
||||
const status: 'locked' | 'expired' = remaining > 0 ? 'locked' : 'expired';
|
||||
const fullName = [row.first_name, row.last_name].filter(Boolean).join(' ') || null;
|
||||
const lockedAtApprox =
|
||||
lockoutMinutes > 0
|
||||
? new Date(lockedUntil.getTime() - lockoutMinutes * 60_000).toISOString()
|
||||
: row.updated_at
|
||||
? new Date(row.updated_at).toISOString()
|
||||
: null;
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
email: safeDecrypt(row.email_encrypted),
|
||||
fullName,
|
||||
phone: safeDecrypt(row.phone_encrypted),
|
||||
failedLoginCount: row.failed_login_count ?? 0,
|
||||
lockedUntil: lockedUntil.toISOString(),
|
||||
lockedAtApprox,
|
||||
remainingMinutes: remaining > 0 ? minutesRemaining(lockedUntil, now) : 0,
|
||||
status,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -4,12 +4,19 @@ import '../../l10n/locale_controller.dart';
|
||||
|
||||
/// User-facing application error with optional HTTP status and API error code.
|
||||
class AppException implements Exception {
|
||||
const AppException(this.message, {this.statusCode, this.code});
|
||||
const AppException(
|
||||
this.message, {
|
||||
this.statusCode,
|
||||
this.code,
|
||||
this.retryAfterMinutes,
|
||||
});
|
||||
|
||||
final String message;
|
||||
final int? statusCode;
|
||||
/// Backend machine code when present (e.g. `EMAIL_NOT_VERIFIED`).
|
||||
final String? code;
|
||||
/// Present for `ACCOUNT_LOCKED` responses.
|
||||
final int? retryAfterMinutes;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
@ -24,6 +31,14 @@ class AppException implements Exception {
|
||||
return en;
|
||||
}
|
||||
|
||||
static String accountLockedMessage(int minutes) {
|
||||
final m = minutes < 1 ? 1 : minutes;
|
||||
return _t(
|
||||
'Your account has been temporarily locked after several unsuccessful login attempts. You can try again in $m minute${m == 1 ? '' : 's'}.',
|
||||
'Votre compte a été temporairement verrouillé après plusieurs tentatives de connexion infructueuses. Vous pourrez réessayer dans $m minute${m == 1 ? '' : 's'}.',
|
||||
);
|
||||
}
|
||||
|
||||
/// Generic unreachable message — covers network issues, timeouts, DNS failures,
|
||||
/// and anything where we never got a meaningful server response. Blaming the
|
||||
/// connection is friendlier than "service unavailable" when the real cause is
|
||||
@ -59,11 +74,22 @@ class AppException implements Exception {
|
||||
if (data is Map) {
|
||||
final msg = data['error'] ?? data['message'];
|
||||
final code = data['code'];
|
||||
final retryRaw = data['retryAfterMinutes'];
|
||||
final retryAfterMinutes = retryRaw is num ? retryRaw.toInt() : null;
|
||||
if (code == 'ACCOUNT_LOCKED') {
|
||||
return AppException(
|
||||
accountLockedMessage(retryAfterMinutes ?? 1),
|
||||
statusCode: status,
|
||||
code: 'ACCOUNT_LOCKED',
|
||||
retryAfterMinutes: retryAfterMinutes,
|
||||
);
|
||||
}
|
||||
if (msg is String && msg.isNotEmpty) {
|
||||
return AppException(
|
||||
sanitizeApiMessage(msg, fallback: fallback),
|
||||
statusCode: status,
|
||||
code: code is String ? code : null,
|
||||
retryAfterMinutes: retryAfterMinutes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,12 +124,20 @@ export function LoginPage() {
|
||||
nav(from, { replace: true });
|
||||
} catch (e: any) {
|
||||
const code = e?.response?.data?.code;
|
||||
const retryAfterMinutes = e?.response?.data?.retryAfterMinutes;
|
||||
const msg =
|
||||
code === 'CAPTCHA_REQUIRED'
|
||||
? t('auth.captchaRequired')
|
||||
: code === 'CAPTCHA_INVALID'
|
||||
? t('auth.captchaInvalid')
|
||||
: apiErrorMessage(e, t('auth.loginFailed'));
|
||||
: code === 'ACCOUNT_LOCKED'
|
||||
? t('auth.accountLocked', {
|
||||
minutes:
|
||||
typeof retryAfterMinutes === 'number' && retryAfterMinutes > 0
|
||||
? retryAfterMinutes
|
||||
: 1,
|
||||
})
|
||||
: apiErrorMessage(e, t('auth.loginFailed'));
|
||||
setError(String(msg));
|
||||
setEmailNotVerified(code === 'EMAIL_NOT_VERIFIED');
|
||||
if (code === 'CAPTCHA_REQUIRED' || code === 'CAPTCHA_INVALID') {
|
||||
|
||||
@ -78,6 +78,18 @@ type AdminNotification = {
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
type LockedAccount = {
|
||||
id: string;
|
||||
email: string | null;
|
||||
fullName: string | null;
|
||||
phone: string | null;
|
||||
failedLoginCount: number;
|
||||
lockedUntil: string;
|
||||
lockedAtApprox: string | null;
|
||||
remainingMinutes: number;
|
||||
status: 'locked' | 'expired';
|
||||
};
|
||||
|
||||
type LedgerCredit = {
|
||||
id: string;
|
||||
userId: string;
|
||||
@ -358,6 +370,32 @@ export function SecurityAdminPage() {
|
||||
refetchInterval: tab === 4 && !wsConnected ? 10_000 : false,
|
||||
});
|
||||
|
||||
const lockedAccountsQ = useQuery({
|
||||
queryKey: ['admin-locked-accounts'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<{ items: LockedAccount[]; total: number }>(
|
||||
'/api/v1/admin/security/locked-accounts'
|
||||
);
|
||||
return res.data;
|
||||
},
|
||||
enabled: tab === 5,
|
||||
refetchInterval: tab === 5 ? 15_000 : false,
|
||||
});
|
||||
|
||||
const unlockAccountMut = useMutation({
|
||||
mutationFn: async (userId: string) => {
|
||||
await api.post(`/api/v1/admin/security/locked-accounts/${userId}/unlock`, {});
|
||||
},
|
||||
onSuccess: () => {
|
||||
void qc.invalidateQueries({ queryKey: ['admin-locked-accounts'] });
|
||||
void qc.invalidateQueries({ queryKey: ['admin-audit-logs'] });
|
||||
setResolveToast(t('admin.security.lockedAccounts.unlocked'));
|
||||
},
|
||||
onError: () => {
|
||||
setResolveToast(t('admin.security.lockedAccounts.unlockFailed'));
|
||||
},
|
||||
});
|
||||
|
||||
const walletTypesQ = useQuery({
|
||||
queryKey: ['wallet-types'],
|
||||
queryFn: async () => {
|
||||
@ -651,6 +689,11 @@ export function SecurityAdminPage() {
|
||||
<Tab label={t('admin.security.tabs.ledgerCredits')} />
|
||||
<Tab label={t('admin.security.tabs.dbAudit', { count: tamperEventsQ.data?.total ?? 0 })} />
|
||||
<Tab label={t('admin.security.tabs.auditLog', { count: auditLogsQ.data?.total ?? 0 })} />
|
||||
<Tab
|
||||
label={t('admin.security.tabs.lockedAccounts', {
|
||||
count: lockedAccountsQ.data?.total ?? 0,
|
||||
})}
|
||||
/>
|
||||
<Tab label={t('admin.security.tabs.alertEmails')} />
|
||||
</Tabs>
|
||||
|
||||
@ -1069,6 +1112,119 @@ export function SecurityAdminPage() {
|
||||
)}
|
||||
|
||||
{tab === 5 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<CardContent>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
spacing={1}
|
||||
sx={{ mb: 2, justifyContent: 'space-between', alignItems: { sm: 'center' } }}
|
||||
>
|
||||
<Box>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800 }}>
|
||||
{t('admin.security.lockedAccounts.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ opacity: 0.7 }}>
|
||||
{t('admin.security.lockedAccounts.subtitle')}
|
||||
</Typography>
|
||||
</Box>
|
||||
<RefreshIconButton
|
||||
onClick={() => void lockedAccountsQ.refetch()}
|
||||
loading={lockedAccountsQ.isFetching}
|
||||
/>
|
||||
</Stack>
|
||||
{lockedAccountsQ.isError && (
|
||||
<Alert severity="error" sx={{ mb: 2 }}>
|
||||
{t('admin.security.lockedAccounts.loadError')}
|
||||
</Alert>
|
||||
)}
|
||||
<ScrollableTable>
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>{t('admin.security.lockedAccounts.identity')}</TableCell>
|
||||
<TableCell>{t('admin.security.lockedAccounts.email')}</TableCell>
|
||||
<TableCell>{t('admin.security.lockedAccounts.failedAttempts')}</TableCell>
|
||||
<TableCell>{t('admin.security.lockedAccounts.lockedAt')}</TableCell>
|
||||
<TableCell>{t('admin.security.lockedAccounts.lockedUntil')}</TableCell>
|
||||
<TableCell>{t('admin.security.lockedAccounts.remaining')}</TableCell>
|
||||
<TableCell>{t('admin.security.lockedAccounts.status')}</TableCell>
|
||||
<TableCell />
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{(lockedAccountsQ.data?.items ?? []).map((row) => (
|
||||
<TableRow key={row.id}>
|
||||
<TableCell>
|
||||
<Typography variant="body2" sx={{ fontWeight: 700 }}>
|
||||
{row.fullName || '—'}
|
||||
</Typography>
|
||||
<Typography variant="caption" sx={{ fontFamily: 'monospace', opacity: 0.7 }}>
|
||||
{row.id.slice(0, 8)}…
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">{row.email || '—'}</Typography>
|
||||
{row.phone && (
|
||||
<Typography variant="caption" sx={{ display: 'block', opacity: 0.7 }}>
|
||||
{row.phone}
|
||||
</Typography>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{row.failedLoginCount}</TableCell>
|
||||
<TableCell>
|
||||
{row.lockedAtApprox
|
||||
? new Date(row.lockedAtApprox).toLocaleString()
|
||||
: '—'}
|
||||
</TableCell>
|
||||
<TableCell>{new Date(row.lockedUntil).toLocaleString()}</TableCell>
|
||||
<TableCell>
|
||||
{row.status === 'locked'
|
||||
? t('admin.security.lockedAccounts.minutes', {
|
||||
count: row.remainingMinutes,
|
||||
})
|
||||
: '—'}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
size="small"
|
||||
color={row.status === 'locked' ? 'warning' : 'default'}
|
||||
label={
|
||||
row.status === 'locked'
|
||||
? t('admin.security.lockedAccounts.statusLocked')
|
||||
: t('admin.security.lockedAccounts.statusExpired')
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
disabled={unlockAccountMut.isPending}
|
||||
onClick={() => unlockAccountMut.mutate(row.id)}
|
||||
>
|
||||
{unlockAccountMut.isPending
|
||||
? t('admin.security.lockedAccounts.unlocking')
|
||||
: t('admin.security.lockedAccounts.unlock')}
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{(lockedAccountsQ.data?.items ?? []).length === 0 &&
|
||||
!lockedAccountsQ.isLoading && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} align="center">
|
||||
{t('admin.security.lockedAccounts.empty')}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</ScrollableTable>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{tab === 6 && (
|
||||
<Card sx={{ borderRadius: 3 }}>
|
||||
<CardContent>
|
||||
<Typography variant="h6" sx={{ fontWeight: 800, mb: 1 }}>
|
||||
|
||||
@ -42,6 +42,9 @@ export function SettingsPage() {
|
||||
rate_limit_window_ms: number;
|
||||
rate_limit_max: number;
|
||||
login_rate_limit_max: number;
|
||||
login_max_failed_attempts: number;
|
||||
login_lockout_minutes: number;
|
||||
login_captcha_after_failures: number;
|
||||
daily_withdrawal_limit_usd: number;
|
||||
large_withdrawal_threshold_usd: number;
|
||||
candle_predict_engine_tick_ms: number;
|
||||
@ -401,6 +404,64 @@ export function SettingsPage() {
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
||||
<Accordion defaultExpanded={false} sx={{ borderRadius: 2, overflow: 'hidden' }}>
|
||||
<AccordionSummary expandIcon={<ExpandMoreRoundedIcon />}>
|
||||
<Box>
|
||||
<Typography sx={{ fontWeight: 900 }}>
|
||||
{t('admin.settings.sections.loginLockout.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ opacity: 0.7 }}>
|
||||
{t('admin.settings.sections.loginLockout.subtitle')}
|
||||
</Typography>
|
||||
</Box>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails>
|
||||
<Box
|
||||
sx={{
|
||||
display: 'grid',
|
||||
gap: 1.5,
|
||||
gridTemplateColumns: { xs: '1fr', md: 'repeat(12, 1fr)' },
|
||||
}}
|
||||
>
|
||||
<Box sx={{ gridColumn: { xs: '1 / -1', md: 'span 4' } }}>
|
||||
<TextField
|
||||
label={t('admin.settings.sections.loginLockout.maxAttempts')}
|
||||
helperText={t('admin.settings.sections.loginLockout.maxAttemptsHint')}
|
||||
type="number"
|
||||
value={effective.login_max_failed_attempts ?? 5}
|
||||
onChange={(e) => set('login_max_failed_attempts', parseNum(e.target.value))}
|
||||
fullWidth
|
||||
slotProps={{ htmlInput: { min: 0, max: 50 } }}
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ gridColumn: { xs: '1 / -1', md: 'span 4' } }}>
|
||||
<TextField
|
||||
label={t('admin.settings.sections.loginLockout.lockoutMinutes')}
|
||||
helperText={t('admin.settings.sections.loginLockout.lockoutMinutesHint')}
|
||||
type="number"
|
||||
value={effective.login_lockout_minutes ?? 15}
|
||||
onChange={(e) => set('login_lockout_minutes', parseNum(e.target.value))}
|
||||
fullWidth
|
||||
slotProps={{ htmlInput: { min: 0, max: 1440 } }}
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ gridColumn: { xs: '1 / -1', md: 'span 4' } }}>
|
||||
<TextField
|
||||
label={t('admin.settings.sections.loginLockout.captchaAfter')}
|
||||
helperText={t('admin.settings.sections.loginLockout.captchaAfterHint')}
|
||||
type="number"
|
||||
value={effective.login_captcha_after_failures ?? 3}
|
||||
onChange={(e) =>
|
||||
set('login_captcha_after_failures', parseNum(e.target.value))
|
||||
}
|
||||
fullWidth
|
||||
slotProps={{ htmlInput: { min: 0, max: 20 } }}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
||||
<Accordion defaultExpanded={false} sx={{ borderRadius: 2, overflow: 'hidden' }}>
|
||||
<AccordionSummary expandIcon={<ExpandMoreRoundedIcon />}>
|
||||
<Box>
|
||||
|
||||
@ -96,6 +96,8 @@ export const en = {
|
||||
enterEmailFirst: 'Enter your email address first.',
|
||||
emailPasswordRequired: 'Email and password are required.',
|
||||
loginFailed: 'Login failed',
|
||||
accountLocked:
|
||||
'Your account has been temporarily locked after several unsuccessful login attempts. You can try again in {{minutes}} minute(s).',
|
||||
captchaRequired: 'Complete the security check below and try again.',
|
||||
captchaInvalid: 'Security check failed. Please try again.',
|
||||
resendFailed: 'Failed to resend verification email',
|
||||
@ -1349,6 +1351,7 @@ export const en = {
|
||||
ledgerCredits: 'Ledger credits',
|
||||
dbAudit: 'DB audit ({{count}})',
|
||||
auditLog: 'Audit log ({{count}})',
|
||||
lockedAccounts: 'Locked accounts ({{count}})',
|
||||
alertEmails: 'Alert emails',
|
||||
},
|
||||
alerts: {
|
||||
@ -1432,6 +1435,27 @@ export const en = {
|
||||
when: 'When',
|
||||
empty: 'No audit events recorded',
|
||||
},
|
||||
lockedAccounts: {
|
||||
title: 'Temporarily locked accounts',
|
||||
subtitle:
|
||||
'Accounts locked after too many failed login attempts. Unlock resets the failure counter immediately.',
|
||||
loadError: 'Failed to load locked accounts.',
|
||||
identity: 'Identity',
|
||||
email: 'Email / phone',
|
||||
failedAttempts: 'Failed attempts',
|
||||
lockedAt: 'Locked at (approx.)',
|
||||
lockedUntil: 'Locked until',
|
||||
remaining: 'Time remaining',
|
||||
status: 'Status',
|
||||
statusLocked: 'Locked',
|
||||
statusExpired: 'Expired',
|
||||
unlock: 'Unlock',
|
||||
unlocking: 'Unlocking…',
|
||||
unlocked: 'Account unlocked.',
|
||||
unlockFailed: 'Failed to unlock account.',
|
||||
empty: 'No temporarily locked accounts',
|
||||
minutes: '{{count}} min',
|
||||
},
|
||||
alertEmails: {
|
||||
title: 'Security alert emails',
|
||||
subtitle: 'One email per line. Encrypted at rest in the database.',
|
||||
@ -1505,6 +1529,17 @@ export const en = {
|
||||
apiMax: 'API max requests / window',
|
||||
loginMax: 'Login max attempts / 15 min',
|
||||
},
|
||||
loginLockout: {
|
||||
title: 'Account login lockout',
|
||||
subtitle:
|
||||
'Temporarily lock accounts after repeated failed password or 2FA attempts. Takes effect immediately.',
|
||||
maxAttempts: 'Max failed attempts before lock',
|
||||
maxAttemptsHint: '0 = disable lockout by attempt count',
|
||||
lockoutMinutes: 'Lockout duration (minutes)',
|
||||
lockoutMinutesHint: '0 = disable temporary lockout (max 1440 = 24h)',
|
||||
captchaAfter: 'Show captcha after N failures',
|
||||
captchaAfterHint: 'Requires captcha to be configured on the server',
|
||||
},
|
||||
candlePredict: {
|
||||
title: 'Candle Predict engine',
|
||||
subtitle: 'Tick interval and backfill pacing (lower backfill = less DB load at scale).',
|
||||
|
||||
@ -97,6 +97,8 @@ export const fr = {
|
||||
enterEmailFirst: 'Saisissez d’abord votre adresse e-mail.',
|
||||
emailPasswordRequired: 'L’e-mail et le mot de passe sont obligatoires.',
|
||||
loginFailed: 'Échec de la connexion',
|
||||
accountLocked:
|
||||
'Votre compte a été temporairement verrouillé après plusieurs tentatives de connexion infructueuses. Vous pourrez réessayer dans {{minutes}} minute(s).',
|
||||
captchaRequired: 'Complétez la vérification de sécurité ci-dessous et réessayez.',
|
||||
captchaInvalid: 'Échec de la vérification de sécurité. Veuillez réessayer.',
|
||||
resendFailed: 'Échec de l’envoi de l’e-mail de vérification',
|
||||
@ -1362,6 +1364,7 @@ export const fr = {
|
||||
ledgerCredits: 'Crédits grand livre',
|
||||
dbAudit: 'Audit DB ({{count}})',
|
||||
auditLog: 'Journal d’audit ({{count}})',
|
||||
lockedAccounts: 'Comptes verrouillés ({{count}})',
|
||||
alertEmails: 'E-mails d’alerte',
|
||||
},
|
||||
alerts: {
|
||||
@ -1446,6 +1449,27 @@ export const fr = {
|
||||
when: 'Quand',
|
||||
empty: 'Aucun événement d’audit enregistré',
|
||||
},
|
||||
lockedAccounts: {
|
||||
title: 'Comptes temporairement verrouillés',
|
||||
subtitle:
|
||||
'Comptes verrouillés après trop de tentatives de connexion échouées. Le déverrouillage réinitialise immédiatement le compteur.',
|
||||
loadError: 'Impossible de charger les comptes verrouillés.',
|
||||
identity: 'Identité',
|
||||
email: 'E-mail / téléphone',
|
||||
failedAttempts: 'Tentatives échouées',
|
||||
lockedAt: 'Verrouillé à (approx.)',
|
||||
lockedUntil: 'Verrouillé jusqu’à',
|
||||
remaining: 'Temps restant',
|
||||
status: 'Statut',
|
||||
statusLocked: 'Verrouillé',
|
||||
statusExpired: 'Expiré',
|
||||
unlock: 'Déverrouiller',
|
||||
unlocking: 'Déverrouillage…',
|
||||
unlocked: 'Compte déverrouillé.',
|
||||
unlockFailed: 'Échec du déverrouillage.',
|
||||
empty: 'Aucun compte temporairement verrouillé',
|
||||
minutes: '{{count}} min',
|
||||
},
|
||||
alertEmails: {
|
||||
title: 'E-mails d’alerte sécurité',
|
||||
subtitle: 'Un e-mail par ligne. Chiffré au repos dans la base de données.',
|
||||
@ -1519,6 +1543,17 @@ export const fr = {
|
||||
apiMax: 'Requêtes API max / fenêtre',
|
||||
loginMax: 'Tentatives de connexion max / 15 min',
|
||||
},
|
||||
loginLockout: {
|
||||
title: 'Verrouillage temporaire des comptes',
|
||||
subtitle:
|
||||
'Verrouille temporairement un compte après plusieurs échecs mot de passe ou 2FA. Prend effet immédiatement.',
|
||||
maxAttempts: 'Tentatives échouées max avant verrouillage',
|
||||
maxAttemptsHint: '0 = désactiver le verrouillage par nombre de tentatives',
|
||||
lockoutMinutes: 'Durée du verrouillage (minutes)',
|
||||
lockoutMinutesHint: '0 = désactiver (max 1440 = 24 h)',
|
||||
captchaAfter: 'Afficher le captcha après N échecs',
|
||||
captchaAfterHint: 'Nécessite un captcha configuré sur le serveur',
|
||||
},
|
||||
candlePredict: {
|
||||
title: 'Moteur Candle Predict',
|
||||
subtitle: 'Intervalle de tick et rythme de backfill (backfill plus bas = moins de charge DB à l’échelle).',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user