Updates
This commit is contained in:
Vendored
+7
-5
@@ -14,8 +14,8 @@ export = sendEmailCode;
|
||||
* @param {String} [params.key] - FULL ACCESS API Key
|
||||
* @param {String} [params.database] - Target Database
|
||||
* @param {string} params.email Login Email/Username and Password
|
||||
* @param {http.ServerResponse} [params.response] - Http response object
|
||||
* @param {string} [params.temp_code_field_name] - Database table field name for temporary code
|
||||
* @param {http.ServerResponse & Object<string,any>} [params.response]
|
||||
* @param {string} [params.mail_domain]
|
||||
* @param {string} [params.mail_username]
|
||||
* @param {string} [params.mail_password]
|
||||
@@ -24,14 +24,16 @@ export = sendEmailCode;
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns { Promise<boolean>}
|
||||
* @returns { Promise<import("../package-shared/types").SendOneTimeCodeEmailResponse>}
|
||||
*/
|
||||
declare function sendEmailCode({ key, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, user_id, useLocal, }: {
|
||||
declare function sendEmailCode({ key, email, database, temp_code_field_name, mail_domain, mail_password, mail_username, mail_port, sender, user_id, useLocal, response, }: {
|
||||
key?: string;
|
||||
database?: string;
|
||||
email: string;
|
||||
response?: http.ServerResponse;
|
||||
temp_code_field_name?: string;
|
||||
response?: http.ServerResponse & {
|
||||
[x: string]: any;
|
||||
};
|
||||
mail_domain?: string;
|
||||
mail_username?: string;
|
||||
mail_password?: string;
|
||||
@@ -39,5 +41,5 @@ declare function sendEmailCode({ key, email, database, temp_code_field_name, mai
|
||||
sender?: string;
|
||||
user_id?: boolean;
|
||||
useLocal?: boolean;
|
||||
}): Promise<boolean>;
|
||||
}): Promise<import("../package-shared/types").SendOneTimeCodeEmailResponse>;
|
||||
import http = require("http");
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* ==============================================================================
|
||||
*/
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
@@ -28,8 +27,8 @@ const apiSendEmailCode = require("../package-shared/functions/api/users/api-send
|
||||
* @param {String} [params.key] - FULL ACCESS API Key
|
||||
* @param {String} [params.database] - Target Database
|
||||
* @param {string} params.email Login Email/Username and Password
|
||||
* @param {http.ServerResponse} [params.response] - Http response object
|
||||
* @param {string} [params.temp_code_field_name] - Database table field name for temporary code
|
||||
* @param {http.ServerResponse & Object<string,any>} [params.response]
|
||||
* @param {string} [params.mail_domain]
|
||||
* @param {string} [params.mail_username]
|
||||
* @param {string} [params.mail_password]
|
||||
@@ -38,7 +37,7 @@ const apiSendEmailCode = require("../package-shared/functions/api/users/api-send
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
* @param {boolean} [params.useLocal]
|
||||
*
|
||||
* @returns { Promise<boolean>}
|
||||
* @returns { Promise<import("../package-shared/types").SendOneTimeCodeEmailResponse>}
|
||||
*/
|
||||
async function sendEmailCode({
|
||||
key,
|
||||
@@ -52,6 +51,7 @@ async function sendEmailCode({
|
||||
sender,
|
||||
user_id,
|
||||
useLocal,
|
||||
response,
|
||||
}) {
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@@ -66,11 +66,6 @@ async function sendEmailCode({
|
||||
"utf-8"
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize HTTP response variable
|
||||
*/
|
||||
let httpResponse;
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
*
|
||||
@@ -97,7 +92,7 @@ async function sendEmailCode({
|
||||
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
|
||||
} catch (error) {}
|
||||
|
||||
httpResponse = await apiSendEmailCode({
|
||||
return await apiSendEmailCode({
|
||||
database: DSQL_DB_NAME,
|
||||
email,
|
||||
email_login_field: emailLoginTempCodeFieldName,
|
||||
@@ -108,6 +103,7 @@ async function sendEmailCode({
|
||||
mail_username,
|
||||
sender,
|
||||
useLocal,
|
||||
response,
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
@@ -115,9 +111,9 @@ async function sendEmailCode({
|
||||
*
|
||||
* @description make a request to datasquirel.com
|
||||
*
|
||||
* @type {{ success: boolean, payload: import("../package-shared/types").DATASQUIREL_LoggedInUser | null, userId?: number, msg?: string }}
|
||||
* @type {import("../package-shared/types").SendOneTimeCodeEmailResponse}
|
||||
*/
|
||||
httpResponse = await new Promise((resolve, reject) => {
|
||||
const httpResponse = await new Promise((resolve, reject) => {
|
||||
const reqPayload = JSON.stringify({
|
||||
email,
|
||||
database,
|
||||
@@ -173,22 +169,8 @@ async function sendEmailCode({
|
||||
httpsRequest.write(reqPayload);
|
||||
httpsRequest.end();
|
||||
});
|
||||
}
|
||||
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
|
||||
/**
|
||||
* Make https request
|
||||
*
|
||||
* @description make a request to datasquirel.com
|
||||
*/
|
||||
if (httpResponse?.success) {
|
||||
return true;
|
||||
} else {
|
||||
console.log(httpResponse);
|
||||
return false;
|
||||
return httpResponse;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
export = validateTempEmailCode;
|
||||
/**
|
||||
* Verify the temp email code sent to the user's email address
|
||||
* ==============================================================================
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {http.IncomingMessage & Object<string, any>} params.request
|
||||
* @param {string} [params.email]
|
||||
*
|
||||
* @returns { Promise<boolean>}
|
||||
*/
|
||||
declare function validateTempEmailCode({ request, email }: {
|
||||
request: http.IncomingMessage & {
|
||||
[x: string]: any;
|
||||
};
|
||||
email?: string;
|
||||
}): Promise<boolean>;
|
||||
import http = require("http");
|
||||
@@ -0,0 +1,53 @@
|
||||
// @ts-check
|
||||
|
||||
const http = require("http");
|
||||
const getAuthCookieNames = require("../package-shared/functions/backend/cookies/get-auth-cookie-names");
|
||||
const parseCookies = require("../package-shared/utils/backend/parseCookies");
|
||||
const decrypt = require("../package-shared/functions/dsql/decrypt");
|
||||
const EJSON = require("../package-shared/utils/ejson");
|
||||
|
||||
/**
|
||||
* Verify the temp email code sent to the user's email address
|
||||
* ==============================================================================
|
||||
* @async
|
||||
*
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {http.IncomingMessage & Object<string, any>} params.request
|
||||
* @param {string} [params.email]
|
||||
*
|
||||
* @returns { Promise<boolean>}
|
||||
*/
|
||||
async function validateTempEmailCode({ request, email }) {
|
||||
try {
|
||||
const keyNames = getAuthCookieNames();
|
||||
const oneTimeCodeCookieName = keyNames.oneTimeCodeName;
|
||||
|
||||
const cookies = parseCookies({ request });
|
||||
const encryptedOneTimeCode = cookies[oneTimeCodeCookieName];
|
||||
|
||||
const encryptedPayload = decrypt({
|
||||
encryptedString: encryptedOneTimeCode,
|
||||
});
|
||||
|
||||
const payload =
|
||||
/** @type {import("../package-shared/types").SendOneTimeCodeEmailResponse | undefined} */ (
|
||||
EJSON.parse(encryptedPayload)
|
||||
);
|
||||
|
||||
if (payload?.email && !email) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (payload?.email && payload.email === email) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log("validateTempEmailCode error:", error.message);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = validateTempEmailCode;
|
||||
Reference in New Issue
Block a user