initiatePasswordReset static method
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 {
if (AuthConfig.current.sendPasswordResetEmail == null) {
session.log(
'ResetPasswordEmail is not configured, cannot send email.',
level: LogLevel.debug,
);
return false;
}
email = email.trim().toLowerCase();
var userInfo = await Users.findUserByEmail(session, email);
if (userInfo == null) {
session.log(
"User with email: '$email' is not found!",
level: LogLevel.debug,
);
return false;
}
var verificationCode = _generateVerificationCode();
var emailReset = EmailReset(
userId: userInfo.id!,
verificationCode: verificationCode,
expiration: DateTime.now()
.add(
AuthConfig.current.passwordResetExpirationTime,
)
.toUtc(),
);
await EmailReset.db.insertRow(session, emailReset);
return AuthConfig.current.sendPasswordResetEmail!(
session,
userInfo,
verificationCode,
);
}