deletePasswordResetRequests method
Future<void>
deletePasswordResetRequests(
- Session session, {
- required Duration? olderThan,
- required UuidValue? emailAccountId,
- required Transaction transaction,
Deletes password reset requests according to olderThan.
If olderThan is Duration.zero, this removes all matching requests,
including those timestamped at or after the current time.
If olderThan is null, this will remove all expired password reset
requests, as configured by the
EmailIdpConfig.passwordResetVerificationCodeLifetime.
Other durations remove only requests strictly older than olderThan.
If emailAccountId is provided, only requests for the given email account
will be deleted.
Implementation
Future<void> deletePasswordResetRequests(
Session session, {
required Duration? olderThan,
required UuidValue? emailAccountId,
required Transaction transaction,
}) async {
final lastValidDateTime = olderThan == Duration.zero
? null
: clock.now().subtract(
olderThan ?? _config.passwordResetVerificationCodeLifetime,
);
await EmailAccountPasswordResetRequest.db.deleteWhere(
session,
where: (t) {
Expression expression = Constant.bool(true);
if (lastValidDateTime != null) {
expression &= t.createdAt < lastValidDateTime;
}
if (emailAccountId != null) {
expression &= t.emailAccountId.equals(emailAccountId);
}
return expression;
},
transaction: transaction,
);
}