Added reset password function + basic mail layout
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user