@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
68 lines (64 loc) • 2.44 kB
JavaScript
;
/* Send a password reset email */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const site_url_1 = __importDefault(require("@cocalc/server/settings/site-url"));
const smtp_1 = __importDefault(require("./smtp"));
const sendgrid_1 = __importDefault(require("./sendgrid"));
const settings_1 = require("@cocalc/server/settings");
async function sendPasswordResetEmail(email_address, // target email_address of user who will receive the password reset email
id // the secret code that they must supply to reset their password
) {
const subject = "Password Reset";
const { html, text } = await getMessage(email_address, id);
const message = { to: email_address, subject, html, text };
try {
await (0, smtp_1.default)(message, "password_reset");
}
catch (err) {
console.log(`sending password reset via secondary smtp server failed; trying sendgrid -- ${err}`);
await (0, sendgrid_1.default)(message);
}
}
exports.default = sendPasswordResetEmail;
async function getMessage(email_address, id) {
const { help_email, site_name } = await (0, settings_1.getServerSettings)();
const site_url = await (0, site_url_1.default)();
const reset_url = `${site_url}/auth/password-reset/${id}`;
let html = `
<div>
Hello,
<br/>
<br/>
Somebody just requested to change the password of your ${site_name ?? "OpenCoCalc"} account with email address <b>${email_address}</b>.
If you requested this password change, please click this link:
<div style="text-align: center; font-size: 120%; margin:30px 0">
<b><a href="${reset_url}">${reset_url}</a></b>
</div>
<br/>
If you don't want to change your password, ignore this message.
`;
if (help_email) {
html += `
<br/>
<br/>
In case of problems, email
<a href="mailto:${help_email}">${help_email}</a>.
`;
}
let text = `
Hello,
Somebody just requested to change the password of your
${site_name ?? "OpenCoCalc"} account with email address ${email_address}.
If you requested this password change, visit this URL:
${reset_url}
If you don't want to change your password, ignore this message.
`;
if (help_email) {
text += `\n\nIn case of problems, email ${help_email}.\n`;
}
return { html, text };
}
//# sourceMappingURL=password-reset.js.map