Self-service password reset
This commit is contained in:
39
server/utils/email.ts
Normal file
39
server/utils/email.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import nodemailer from 'nodemailer'
|
||||
|
||||
export async function sendPasswordResetEmail(email: string, code: string) {
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: config.emailHost,
|
||||
port: parseInt(config.emailPort),
|
||||
secure: parseInt(config.emailPort) === 465,
|
||||
auth: {
|
||||
user: config.emailUser,
|
||||
pass: config.emailPassword,
|
||||
},
|
||||
})
|
||||
|
||||
const mailOptions = {
|
||||
from: config.emailFrom,
|
||||
to: email,
|
||||
subject: 'Password Reset Code - New Life Christian Church',
|
||||
text: `Please enter this 6 digit code to reset your password for the New Life Christian Church sermon page: ${code}`,
|
||||
html: `
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
|
||||
<h2 style="color: #333;">Password Reset Request</h2>
|
||||
<p>Please enter this 6 digit code to reset your password for the New Life Christian Church sermon page:</p>
|
||||
<div style="background-color: #f4f4f4; padding: 20px; text-align: center; font-size: 32px; font-weight: bold; letter-spacing: 5px; margin: 20px 0;">
|
||||
${code}
|
||||
</div>
|
||||
<p style="color: #666;">This code will expire in 15 minutes.</p>
|
||||
<p style="color: #666;">If you did not request a password reset, please ignore this email.</p>
|
||||
</div>
|
||||
`,
|
||||
}
|
||||
|
||||
await transporter.sendMail(mailOptions)
|
||||
}
|
||||
|
||||
export function generateResetCode(): string {
|
||||
return Math.floor(100000 + Math.random() * 900000).toString()
|
||||
}
|
||||
Reference in New Issue
Block a user