63 lines
2.8 KiB
JavaScript
63 lines
2.8 KiB
JavaScript
"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());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = sendEmailCode;
|
|
const api_send_email_code_1 = __importDefault(require("../../functions/api/users/api-send-email-code"));
|
|
const grab_api_path_1 = __importDefault(require("../../utils/backend/users/grab-api-path"));
|
|
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
|
|
/**
|
|
* # Send Email Code to a User
|
|
*/
|
|
function sendEmailCode(params) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const { apiKey, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, response, extraCookies, useLocal, apiVersion, dbUserId, } = params;
|
|
const defaultTempLoginFieldName = "temp_login_code";
|
|
const emailLoginTempCodeFieldName = temp_code_field_name
|
|
? temp_code_field_name
|
|
: defaultTempLoginFieldName;
|
|
const emailHtml = `<p>Please use this code to login</p>\n<h2>{{code}}</h2>\n<p>Please note that this code expires after 15 minutes</p>`;
|
|
const apiSendEmailCodeParams = {
|
|
database,
|
|
email,
|
|
email_login_field: emailLoginTempCodeFieldName,
|
|
html: emailHtml,
|
|
mail_domain,
|
|
mail_password,
|
|
mail_port,
|
|
mail_username,
|
|
sender,
|
|
response,
|
|
extraCookies,
|
|
dbUserId,
|
|
};
|
|
if (useLocal) {
|
|
return yield (0, api_send_email_code_1.default)(apiSendEmailCodeParams);
|
|
}
|
|
else {
|
|
const httpResponse = yield (0, query_dsql_api_1.default)({
|
|
path: (0, grab_api_path_1.default)({
|
|
paradigm: "auth",
|
|
action: "send-email-code",
|
|
database,
|
|
apiVersion,
|
|
}),
|
|
apiKey,
|
|
body: apiSendEmailCodeParams,
|
|
method: "POST",
|
|
});
|
|
return httpResponse;
|
|
}
|
|
});
|
|
}
|