forked from noxious/server
Added pw token expiry check, temporarily commented mailer code due to bugs
This commit is contained in:
parent
a4e96f9ede
commit
82f51b2b7e
@ -65,13 +65,16 @@ class UserService {
|
|||||||
const user = await UserRepository.getByEmail(email)
|
const user = await UserRepository.getByEmail(email)
|
||||||
if ( !user ) return
|
if ( !user ) return
|
||||||
const token = await bcrypt.genSalt(10)
|
const token = await bcrypt.genSalt(10)
|
||||||
|
const latestToken = await prisma.passwordResetToken.findFirst({ where: { userId: user.id } })
|
||||||
|
|
||||||
//Check if password reset has been requested recently
|
//Check if password reset has been requested recently
|
||||||
if (await prisma.passwordResetToken.findFirst({
|
if (latestToken) {
|
||||||
where: {
|
|
||||||
userId: user.id
|
const tokenExpiryDate = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||||
},
|
const isTokenExpired = latestToken.createdAt < tokenExpiryDate
|
||||||
})) return
|
|
||||||
|
if (!isTokenExpired) return
|
||||||
|
}
|
||||||
|
|
||||||
prisma.passwordResetToken.create({
|
prisma.passwordResetToken.create({
|
||||||
data: {
|
data: {
|
||||||
@ -80,29 +83,31 @@ class UserService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const transporter = NodeMailer.createTransport({
|
return
|
||||||
host: config.SMTP_HOST,
|
|
||||||
port: config.SMTP_PORT,
|
|
||||||
secure: false,
|
|
||||||
auth: {
|
|
||||||
user: config.SMTP_USER,
|
|
||||||
pass: config.SMTP_PASSWORD,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const info = await transporter.sendMail({
|
// const transporter = NodeMailer.createTransport({
|
||||||
from: config.SMTP_USER,
|
// host: config.SMTP_HOST,
|
||||||
to: email,
|
// port: config.SMTP_PORT,
|
||||||
subject: "Reset your password",
|
// secure: false,
|
||||||
text: "A password reset has been requested, reset your password here: " + config.CLIENT_URL + "/" + token, // Plain text body
|
// auth: {
|
||||||
html: "<p>A password reset has been requested, reset your password here: " + config.CLIENT_URL + "/" + token + "</p>", // Html body
|
// user: config.SMTP_USER,
|
||||||
});
|
// pass: config.SMTP_PASSWORD,
|
||||||
console.log("Message sent: %s", info.messageId);
|
// },
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// const info = await transporter.sendMail({
|
||||||
|
// from: config.SMTP_USER,
|
||||||
|
// to: email,
|
||||||
|
// subject: "Reset your password",
|
||||||
|
// text: "A password reset has been requested, reset your password here: " + config.CLIENT_URL + "/" + token, // Plain text body
|
||||||
|
// html: "<p>A password reset has been requested, reset your password here: " + config.CLIENT_URL + "/" + token + "</p>", // Html body
|
||||||
|
// });
|
||||||
|
// console.log("Message sent: %s", info.messageId);
|
||||||
|
|
||||||
|
|
||||||
if (info) {
|
// if (info) {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user