Implemented cooldown before User is able to resend confirmation code for 2fa

This commit is contained in:
Arseni
2025-12-23 14:56:47 +03:00
parent 1ed76f7243
commit ec54579921
6 changed files with 196 additions and 9 deletions

View File

@@ -11,6 +11,8 @@ class PendingLogin {
final String destination;
final int ttlSeconds;
final SessionIdentifier session;
final int? cooldownSeconds;
final DateTime? cooldownUntil;
const PendingLogin({
required this.account,
@@ -18,6 +20,8 @@ class PendingLogin {
required this.destination,
required this.ttlSeconds,
required this.session,
this.cooldownSeconds,
this.cooldownUntil,
});
factory PendingLogin.fromResponse(
@@ -30,4 +34,30 @@ class PendingLogin {
ttlSeconds: response.ttlSeconds,
session: session,
);
PendingLogin copyWith({
Account? account,
TokenData? pendingToken,
String? destination,
int? ttlSeconds,
SessionIdentifier? session,
int? cooldownSeconds,
DateTime? cooldownUntil,
bool clearCooldown = false,
}) {
return PendingLogin(
account: account ?? this.account,
pendingToken: pendingToken ?? this.pendingToken,
destination: destination ?? this.destination,
ttlSeconds: ttlSeconds ?? this.ttlSeconds,
session: session ?? this.session,
cooldownSeconds: clearCooldown ? null : cooldownSeconds ?? this.cooldownSeconds,
cooldownUntil: clearCooldown ? null : cooldownUntil ?? this.cooldownUntil,
);
}
int get cooldownRemainingSeconds {
final remaining = cooldownUntil?.difference(DateTime.now()).inSeconds ?? 0;
return remaining < 0 ? 0 : remaining;
}
}