resetPassword static method
Resets a users password using a password reset verification code.
Implementation
static Future<bool> resetPassword(
Session session,
String verificationCode,
String password,
) async {
var passwordReset = await EmailReset.db.findFirstRow(session, where: (t) {
return t.verificationCode.equals(verificationCode) &
(t.expiration > DateTime.now().toUtc());
});
if (passwordReset == null) {
session.log(
'Verification code is invalid or has expired!',
level: LogLevel.debug,
);
return false;
}
var emailAuth = await EmailAuth.db.findFirstRow(session, where: (t) {
return t.userId.equals(passwordReset.userId);
});
if (emailAuth == null) {
session.log(
"ser with id: '${passwordReset.userId}' has no email authentication!",
level: LogLevel.debug,
);
return false;
}
emailAuth.hash = await generatePasswordHash(password);
await EmailAuth.db.updateRow(session, emailAuth);
return true;
}