Implemented cooldown before User is able to resend confirmation code for 2fa
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user