initiatePasswordReset static method

Future<bool> initiatePasswordReset(
  1. Session session,
  2. String email
)

Initiates the password reset procedure. Will send an email to the provided address with a reset code.

Implementation

static Future<bool> initiatePasswordReset(
  Session session,
  String email,
) async {
  assert(
    AuthConfig.current.sendPasswordResetEmail != null,
    'ResetPasswordEmail is not configured, cannot send email.',
  );

  email = email.trim().toLowerCase();

  var userInfo = await Users.findUserByEmail(session, email);
  if (userInfo == null) return false;

  var verificationCode = _generateVerificationCode();
  var emailReset = EmailReset(
    userId: userInfo.id!,
    verificationCode: verificationCode,
    expiration: DateTime.now().add(
      AuthConfig.current.passwordResetExpirationTime,
    ),
  );
  await session.db.insert(emailReset);

  return AuthConfig.current.sendPasswordResetEmail!(
    session,
    userInfo,
    verificationCode,
  );
}