The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
feat: send reset password email
Ephraim Atta-Duncan66b529a841f2
diff --git a/apps/web/pages/api/auth/forgot-password.ts b/apps/web/pages/api/auth/forgot-password.tsindex 1a861362f..221be3d1c 100644--- a/apps/web/pages/api/auth/forgot-password.ts+++ b/apps/web/pages/api/auth/forgot-password.ts@@ -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();}diff --git a/packages/lib/mail/baseTemplate.ts b/packages/lib/mail/baseTemplate.tsindex 6741a87b5..6e18c7114 100644--- a/packages/lib/mail/baseTemplate.ts+++ b/packages/lib/mail/baseTemplate.ts@@ -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}diff --git a/packages/lib/mail/index.ts b/packages/lib/mail/index.tsindex 6d49cdb6b..8388608c6 100644--- a/packages/lib/mail/index.ts+++ b/packages/lib/mail/index.ts@@ -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";diff --git a/packages/lib/mail/resetPasswordTemplate.ts b/packages/lib/mail/resetPasswordTemplate.tsnew file mode 100644index 000000000..b86b404fd--- /dev/null+++ b/packages/lib/mail/resetPasswordTemplate.ts@@ -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:[email protected]">[email protected]</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;diff --git a/packages/lib/mail/sendMail.ts b/packages/lib/mail/sendMail.tsindex 101981f12..fd7c6fb61 100644--- a/packages/lib/mail/sendMail.ts+++ b/packages/lib/mail/sendMail.ts@@ -1,4 +1,3 @@-import { ReadStream } from "fs";import nodemailer from "nodemailer";import nodemailerSendgrid from "nodemailer-sendgrid";diff --git a/packages/lib/mail/sendResetPassword.ts b/packages/lib/mail/sendResetPassword.tsnew file mode 100644index 000000000..fd918b470--- /dev/null+++ b/packages/lib/mail/sendResetPassword.ts@@ -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;+ });+};