@a11ywatch/core
Version:
a11ywatch central API
46 lines • 2.28 kB
JavaScript
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.forgotPassword = void 0;
const html_1 = require("../../../../html");
const strings_1 = require("../../../strings");
const utils_1 = require("../../../utils");
const find_1 = require("../find");
const forgotPassword = ({ email }) => __awaiter(void 0, void 0, void 0, function* () {
if (!email) {
throw new Error(strings_1.EMAIL_ERROR);
}
const [user, collection] = yield (0, find_1.getUser)({ email }).catch((_) => {
return [];
});
if (user) {
const resetCode = yield (0, utils_1.asyncRandomGenerate)();
yield collection.findOneAndUpdate({ id: user.id }, { $set: { resetCode } });
utils_1.transporter.sendMail({
from: utils_1.mailOptions.from,
text: utils_1.mailOptions.text,
to: user.email,
subject: `A11yWatch - Password reset.`,
html: `${html_1.logoSvg}<br />
<h1>Reset your password to A11yWatch</h1>
<p style="font-size: 1rem;">Use the code below to reset your password.</p>
<h2 style="margin-top: 18px; font-weight: bold; font-size: 2.3rem;">${resetCode}</h2>
<p style="margin-top: 13px; font-size: 0.85rem;">If you enter the correct reset code you will receive an email with your temporary password.</p>
`,
}, utils_1.sendMailCallback);
return { email: "true" };
}
else {
throw new Error(strings_1.GENERAL_ERROR);
}
});
exports.forgotPassword = forgotPassword;
//# sourceMappingURL=forgot-password.js.map
;