deletePasswordResetAttempts method

Future<void> deletePasswordResetAttempts(
  1. Session session, {
  2. Duration? olderThan,
  3. Transaction? transaction,
})

Cleans up the log of failed password reset attempts older than olderThan.

If olderThan is null, this will remove all attempts outside the time window that is checked upon password reset requets, as configured in EmailAccountConfig.maxPasswordResetAttempts.

Implementation

Future<void> deletePasswordResetAttempts(
  final Session session, {
  Duration? olderThan,
  final Transaction? transaction,
}) async {
  olderThan ??= EmailAccounts.config.maxPasswordResetAttempts.timeframe;

  final removeBefore = clock.now().subtract(olderThan);

  await EmailAccountPasswordResetAttempt.db.deleteWhere(
    session,
    where: (final t) => t.attemptedAt < removeBefore,
    transaction: transaction,
  );
}