verifyEmailPasswordReset static method

Future<EmailPasswordReset?> verifyEmailPasswordReset(
  1. Session session,
  2. String verificationCode
)

Verifies a password reset code, returns a EmailPasswordReset object if successful, null otherwise.

Implementation

static Future<EmailPasswordReset?> verifyEmailPasswordReset(
  Session session,
  String verificationCode,
) async {
  session.log('verificationCode: $verificationCode', level: LogLevel.debug);
  var passwordReset = await session.db.findSingleRow<EmailReset>(
    where: EmailReset.t.verificationCode.equals(verificationCode) &
        (EmailReset.t.expiration > DateTime.now().toUtc()),
  );

  if (passwordReset == null) return null;

  var userInfo = await Users.findUserByUserId(session, passwordReset.userId);
  if (userInfo == null) return null;

  if (userInfo.email == null) return null;

  return EmailPasswordReset(
    userName: userInfo.userName,
    email: userInfo.email!,
  );
}