Added reset password function + basic mail layout

This commit is contained in:
2024-10-27 21:30:33 +01:00
parent 8f8f019ab7
commit 5a36d10f0e
7 changed files with 86 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import bcrypt from 'bcryptjs'
import UserRepository from '../repositories/userRepository'
import prisma from '../utilities/prisma'
import { User } from '@prisma/client'
import config from '../utilities/config'
/**
* User service
@ -53,6 +54,35 @@ class UserService {
}
})
}
/**
* Reset password
* @param email
*/
async resetPassword(email: string): Promise<boolean | User> {
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
host: config.SMTP_HOST,
port: config.SMTP_PORT,
secure: false,
auth: {
user: config.SMTP_USER,
pass: config.SMTP_PASSWORD,
},
});
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: ", // Plain text body
html: "<p>A password reset has been requested, reset your password here: </p>", // Html body
});
console.log("Message sent: %s", info.messageId);
return info.messageId
}
}
export default UserService