UNPKG

@a11ywatch/core

Version:
48 lines 2.94 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.confirmEmail = exports.sendEmailConfirmation = void 0; const date_fns_1 = require("date-fns"); const config_1 = require("../../../../config"); const strings_1 = require("../../../strings"); const utils_1 = require("../../../utils"); const find_1 = require("../find"); const { ROOT_URL } = config_1.config; const sendEmailConfirmation = (user, collection) => __awaiter(void 0, void 0, void 0, function* () { const emailConfirmCode = yield (0, utils_1.asyncRandomGenerate)(); const confirmLink = `${ROOT_URL}/api/confirmEmail?code=${emailConfirmCode}`; const emailExpDate = (0, date_fns_1.addMinutes)(Date.now(), 30); yield collection.findOneAndUpdate({ id: user.id }, { $set: { emailConfirmCode, emailExpDate } }); utils_1.transporter.sendMail(Object.assign(Object.assign({}, utils_1.mailOptions), { to: user.email, subject: `A11yWatch - Email Confirmation.`, html: ` <h1>Click on this link to confirm your email for A11yWatch.</h1> <p>Confirmation code will expire in 30 minutes or you have to get a new link.</p> <div style="padding-top: 20px; padding-bottom: 40px"> <a href="${confirmLink}" aria-label="Confirm your email for A11yWatch" style="margin-top: 8px; margin-bottom: 4px; color: #3f3d56; padding: 8px 15px; border: 1px solid rgba(63, 61, 86, 0.5); text-decoration: none; border-radius: 2px">CONFIRM EMAIL</a> </div> <p style="font-size: 12px; margin-top: 20px">Please do not reply back to this email, it will not be read</p> ` }), utils_1.sendMailCallback); }); exports.sendEmailConfirmation = sendEmailConfirmation; const confirmEmail = ({ keyid: id }) => __awaiter(void 0, void 0, void 0, function* () { if (typeof id === "undefined") { throw new Error(strings_1.EMAIL_ERROR); } const [user, collection] = yield (0, find_1.getUser)({ id }); if (user) { yield (0, exports.sendEmailConfirmation)(user, collection); } else { throw new Error(strings_1.GENERAL_ERROR); } return { code: 200, success: true, message: strings_1.SUCCESS }; }); exports.confirmEmail = confirmEmail; //# sourceMappingURL=confirm-email.js.map