mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: send reset password email
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { sendResetPassword } from "@documenso/lib/mail";
|
||||
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
|
||||
import prisma from "@documenso/prisma";
|
||||
import crypto from "crypto";
|
||||
@ -31,9 +32,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
},
|
||||
});
|
||||
|
||||
console.log(passwordResetToken);
|
||||
|
||||
// TODO: Send token to user via email
|
||||
await sendResetPassword(user, passwordResetToken.token);
|
||||
|
||||
res.status(201).end();
|
||||
}
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
|
||||
export const baseEmailTemplate = (message: string, content: string) => {
|
||||
const html = `
|
||||
<div style="background-color: #eaeaea; padding: 2%;">
|
||||
<div style="text-align:center; margin: auto; font-size: 14px; font-color: #353434; max-width: 500px; border-radius: 0.375rem; background: white; padding: 50px">
|
||||
<div style="text-align:center; margin: auto; font-size: 14px; color: #353434; max-width: 500px; border-radius: 0.375rem; background: white; padding: 50px">
|
||||
<img src="${NEXT_PUBLIC_WEBAPP_URL}/logo_h.png" alt="Documenso Logo" style="width: 180px; display: block; margin: auto; margin-bottom: 14px;">
|
||||
${message}
|
||||
${content}
|
||||
|
||||
@ -2,3 +2,5 @@ export { signingRequestTemplate } from "./signingRequestTemplate";
|
||||
export { signingCompleteTemplate } from "./signingCompleteTemplate";
|
||||
export { sendSigningRequest as sendSigningRequest } from "./sendSigningRequest";
|
||||
export { sendSigningDoneMail } from "./sendSigningDoneMail";
|
||||
export { resetPasswordTemplate } from "./resetPasswordTemplate";
|
||||
export { sendResetPassword } from "./sendResetPassword";
|
||||
|
||||
46
packages/lib/mail/resetPasswordTemplate.ts
Normal file
46
packages/lib/mail/resetPasswordTemplate.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||
|
||||
export const resetPasswordTemplate = (ctaLink: string, ctaLabel: string) => {
|
||||
const customContent = `
|
||||
<h2 style="margin-top: 36px; font-size: 24px; font-weight: bold;">Forgot your password?</h2>
|
||||
<p style="margin-top: 8px;">
|
||||
That's okay, it happens! Click the button below to reset your password.
|
||||
</p>
|
||||
|
||||
<p style="margin: 30px 0px; text-align: center">
|
||||
<a href="${ctaLink}" style="background-color: #37f095; white-space: nowrap; color: white; border-color: transparent; border-width: 1px; border-radius: 0.375rem; font-size: 18px; padding-left: 16px; padding-right: 16px; padding-top: 10px; padding-bottom: 10px; text-decoration: none; margin-top: 4px; margin-bottom: 4px;">
|
||||
${ctaLabel}
|
||||
</a>
|
||||
</p>
|
||||
<p style="margin-top: 20px;">
|
||||
<small>Want to send you own signing links? <a href="https://documenso.com">Hosted Documenso is here!</a>.</small>
|
||||
</p>`;
|
||||
|
||||
const html = `
|
||||
<div style="background-color: #eaeaea; padding: 2%;">
|
||||
<div
|
||||
style="text-align:center; margin: auto; font-size: 14px; color: #353434; max-width: 500px; border-radius: 0.375rem; background: white; padding: 50px">
|
||||
<img src="${NEXT_PUBLIC_WEBAPP_URL}/logo_h.png" alt="Documenso Logo"
|
||||
style="width: 180px; display: block; margin: auto; margin-bottom: 14px;" />
|
||||
${customContent}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const footer = `
|
||||
<div style="text-align: left; line-height: 18px; color: #666666; margin: 24px">
|
||||
<div style="margin-top: 12px">
|
||||
<b>Need help?</b>
|
||||
<br>
|
||||
Contact us at <a href="mailto:hi@documenso.com">hi@documenso.com</a>
|
||||
</div>
|
||||
<hr size="1" style="height: 1px; border: none; color: #D8D8D8; background-color: #D8D8D8">
|
||||
<div style="text-align: center">
|
||||
<small>Easy and beautiful document signing by Documenso.</small>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
return html + footer;
|
||||
};
|
||||
|
||||
export default resetPasswordTemplate;
|
||||
@ -1,4 +1,3 @@
|
||||
import { ReadStream } from "fs";
|
||||
import nodemailer from "nodemailer";
|
||||
import nodemailerSendgrid from "nodemailer-sendgrid";
|
||||
|
||||
|
||||
17
packages/lib/mail/sendResetPassword.ts
Normal file
17
packages/lib/mail/sendResetPassword.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { resetPasswordTemplate } from "@documenso/lib/mail";
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||
import { sendMail } from "./sendMail";
|
||||
import { User } from "@prisma/client";
|
||||
|
||||
export const sendResetPassword = async (user: User, token: string) => {
|
||||
await sendMail(
|
||||
user.email,
|
||||
"Forgot password?",
|
||||
resetPasswordTemplate(
|
||||
`${NEXT_PUBLIC_WEBAPP_URL}/api/auth/reset/${token}`,
|
||||
"Reset Your Password"
|
||||
)
|
||||
).catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user