After configuring captcha2
This commit is contained in:
parent
aea87f2dbb
commit
475951a3a0
@ -310,8 +310,10 @@ export async function login(
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = await settingsRepository.getSettings();
|
const [settings, failedCount] = await Promise.all([
|
||||||
const failedCount = await userRepository.getFailedLoginCount(user.id);
|
settingsRepository.getSettings(),
|
||||||
|
userRepository.getFailedLoginCount(user.id),
|
||||||
|
]);
|
||||||
const afterFailures = settings.login_captcha_after_failures;
|
const afterFailures = settings.login_captcha_after_failures;
|
||||||
if (afterFailures > 0 && failedCount >= afterFailures) {
|
if (afterFailures > 0 && failedCount >= afterFailures) {
|
||||||
try {
|
try {
|
||||||
@ -382,8 +384,10 @@ export async function login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await loginLockoutService.clearLoginFailures(user.id);
|
const [payload] = await Promise.all([
|
||||||
const payload = await buildJwtPayload(user);
|
buildJwtPayload(user),
|
||||||
|
loginLockoutService.clearLoginFailures(user.id),
|
||||||
|
]);
|
||||||
const accessExpiry = settings.access_token_expiry || config.jwt.accessExpiry;
|
const accessExpiry = settings.access_token_expiry || config.jwt.accessExpiry;
|
||||||
const accessToken = jwt.sign(payload, config.jwt.secret, { expiresIn: accessExpiry } as jwt.SignOptions);
|
const accessToken = jwt.sign(payload, config.jwt.secret, { expiresIn: accessExpiry } as jwt.SignOptions);
|
||||||
const refreshToken = uuidv4();
|
const refreshToken = uuidv4();
|
||||||
@ -393,33 +397,40 @@ export async function login(
|
|||||||
ipAddress: auditContext?.ipAddress,
|
ipAddress: auditContext?.ipAddress,
|
||||||
userAgent: auditContext?.userAgent,
|
userAgent: auditContext?.userAgent,
|
||||||
});
|
});
|
||||||
await enforceConcurrentSessionLimit(user.id, auditContext);
|
// Session trim + telemetry must not block the login response.
|
||||||
|
void enforceConcurrentSessionLimit(user.id, auditContext).catch(() => undefined);
|
||||||
if (auditContext) {
|
if (auditContext) {
|
||||||
await auditLogRepository.create({
|
void (async () => {
|
||||||
userId: user.id,
|
try {
|
||||||
action: 'login',
|
await auditLogRepository.create({
|
||||||
ipAddress: auditContext.ipAddress,
|
userId: user.id,
|
||||||
userAgent: auditContext.userAgent,
|
action: 'login',
|
||||||
});
|
ipAddress: auditContext.ipAddress,
|
||||||
queueUserAdminStatsRefresh(user.id);
|
userAgent: auditContext.userAgent,
|
||||||
const fingerprint = await registerLoginFingerprint(
|
});
|
||||||
user.id,
|
queueUserAdminStatsRefresh(user.id);
|
||||||
auditContext.ipAddress,
|
const fingerprint = await registerLoginFingerprint(
|
||||||
auditContext.userAgent
|
user.id,
|
||||||
);
|
auditContext.ipAddress,
|
||||||
const notifyCtx = {
|
auditContext.userAgent
|
||||||
ipAddress: auditContext.ipAddress,
|
);
|
||||||
userAgent: auditContext.userAgent,
|
const notifyCtx = {
|
||||||
countryCode: fingerprint.countryCode,
|
ipAddress: auditContext.ipAddress,
|
||||||
};
|
userAgent: auditContext.userAgent,
|
||||||
if (fingerprint.isNewDevice) {
|
countryCode: fingerprint.countryCode,
|
||||||
void securityNotificationService.notifyNewLogin(user.id, notifyCtx);
|
};
|
||||||
}
|
if (fingerprint.isNewDevice) {
|
||||||
if (fingerprint.isNewCountry && fingerprint.countryCode) {
|
void securityNotificationService.notifyNewLogin(user.id, notifyCtx);
|
||||||
void securityNotificationService.notifyNewCountryLogin(user.id, notifyCtx);
|
}
|
||||||
}
|
if (fingerprint.isNewCountry && fingerprint.countryCode) {
|
||||||
const risk = assessLoginRisk(fingerprint);
|
void securityNotificationService.notifyNewCountryLogin(user.id, notifyCtx);
|
||||||
void recordLoginRisk(user.id, risk, notifyCtx);
|
}
|
||||||
|
const risk = assessLoginRisk(fingerprint);
|
||||||
|
void recordLoginRisk(user.id, risk, notifyCtx);
|
||||||
|
} catch {
|
||||||
|
/* best-effort post-login side effects */
|
||||||
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
void mergeVisitorSupportForUser(user.id, auditContext?.visitorSupportToken);
|
void mergeVisitorSupportForUser(user.id, auditContext?.visitorSupportToken);
|
||||||
const decoded = jwt.decode(accessToken) as { exp: number };
|
const decoded = jwt.decode(accessToken) as { exp: number };
|
||||||
|
|||||||
@ -235,7 +235,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
state.errorMessage != null) {
|
state.errorMessage != null) {
|
||||||
final msg = state.errorMessage!
|
final msg = state.errorMessage!
|
||||||
.replaceFirst('Exception: ', '');
|
.replaceFirst('Exception: ', '');
|
||||||
if (state.isCaptchaChallenge || _captchaRequired) {
|
// Only refresh the math challenge on captcha errors.
|
||||||
|
// Other failures (wrong password/2FA) must keep the current prompt.
|
||||||
|
if (state.isCaptchaChallenge) {
|
||||||
_applyMathChallenge(state.captcha);
|
_applyMathChallenge(state.captcha);
|
||||||
}
|
}
|
||||||
if (state.isEmailNotVerified) {
|
if (state.isEmailNotVerified) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user