1053 lines
40 KiB
JavaScript
1053 lines
40 KiB
JavaScript
"use strict";
|
|
(() => {
|
|
var exports = {};
|
|
exports.id = 7398;
|
|
exports.ids = [7398];
|
|
exports.modules = {
|
|
|
|
/***/ 255:
|
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
|
|
// @ts-check
|
|
/**
|
|
* ==============================================================================
|
|
* Imports
|
|
* ==============================================================================
|
|
*/
|
|
const fs = __webpack_require__(7147);
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
const datasquirel = __webpack_require__(9538);
|
|
const serverError = __webpack_require__(2317);
|
|
const DB_HANDLER = __webpack_require__(9395);
|
|
const addDbEntry = __webpack_require__(7857);
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* Add Admin User on Login
|
|
* ==============================================================================
|
|
*
|
|
* @description this function handles admin users that have been invited by another
|
|
* admin user. This fires when the invited user has been logged in or a new account
|
|
* has been created for the invited user
|
|
*
|
|
* @param {object} params - parameters object
|
|
*
|
|
* @param {object} params.query - query object
|
|
* @param {number} params.query.invite - Invitation user id
|
|
* @param {string} params.query.database_access - String containing authorized databases
|
|
* @param {string} params.query.priviledge - String containing databases priviledges
|
|
* @param {string} params.query.email - Inviting user email address
|
|
*
|
|
* @param {import("@/package-shared/types").UserType} params.user - invited user object
|
|
*
|
|
* @returns {Promise<any>} new user auth object payload
|
|
*/ module.exports = async function addAdminUserOnLogin({ query , user }) {
|
|
try {
|
|
/**
|
|
* Fetch user
|
|
*
|
|
* @description Fetch user from db
|
|
*/ // @ts-ignore
|
|
const { invite , database_access , priviledge , email } = query;
|
|
const lastInviteTimeArray = await DB_HANDLER(`SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?`, [
|
|
invite,
|
|
email
|
|
]);
|
|
// if (lastInviteTimeArray && lastInviteTimeArray[0]?.date_created_code) {
|
|
// const timeSinceLastInvite = Date.now() - parseInt(lastInviteTimeArray[0].date_created_code);
|
|
// if (timeSinceLastInvite > 21600000) {
|
|
// throw new Error("Invitation expired");
|
|
// }
|
|
// } else if (!lastInviteTimeArray || !lastInviteTimeArray[0]) {
|
|
// throw new Error("No Invitation Found");
|
|
// }
|
|
if (!lastInviteTimeArray || !lastInviteTimeArray[0]) {
|
|
throw new Error("No Invitation Found");
|
|
}
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
// @ts-ignore
|
|
const invitingUserDb = await DB_HANDLER(`SELECT first_name,last_name,email FROM users WHERE id=?`, [
|
|
invite
|
|
]);
|
|
if (invitingUserDb?.[0]) {
|
|
const existingUserUser = await DB_HANDLER(`SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?`, [
|
|
invite,
|
|
user.id,
|
|
email
|
|
]);
|
|
if (existingUserUser?.[0]) {
|
|
console.log("User already added");
|
|
} else {
|
|
// const newUserUser = await DB_HANDLER(
|
|
// `INSERT IGNORE INTO user_users
|
|
// (user_id, invited_user_id, database_access, first_name, last_name, phone, email, username, user_type, user_priviledge)
|
|
// VALUES
|
|
// (?,?,?,?,?,?,?,?,?,?)
|
|
// )`,
|
|
// [
|
|
// invite,
|
|
// user.id,
|
|
// database_access,
|
|
// user.first_name,
|
|
// user.last_name,
|
|
// user.phone,
|
|
// user.email,
|
|
// user.username,
|
|
// "admin",
|
|
// priviledge,
|
|
// ]
|
|
// );
|
|
addDbEntry({
|
|
dbFullName: "datasquirel",
|
|
tableName: "user_users",
|
|
data: {
|
|
user_id: invite,
|
|
invited_user_id: user.id,
|
|
database_access: database_access,
|
|
first_name: user.first_name,
|
|
last_name: user.last_name,
|
|
phone: user.phone,
|
|
email: user.email,
|
|
username: user.username,
|
|
user_type: "admin",
|
|
user_priviledge: priviledge,
|
|
image: user.image,
|
|
image_thumbnail: user.image_thumbnail
|
|
}
|
|
});
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
// @ts-ignore
|
|
const dbTableData = await DB_HANDLER(`SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?`, [
|
|
invite,
|
|
email
|
|
]);
|
|
// @ts-ignore
|
|
const clearEntries = await DB_HANDLER(`DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?`, [
|
|
invite,
|
|
user.id
|
|
]);
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
if (dbTableData && dbTableData[0]) {
|
|
const dbTableEntries = dbTableData[0].db_tables_data.split("|");
|
|
for(let i = 0; i < dbTableEntries.length; i++){
|
|
const dbTableEntry = dbTableEntries[i];
|
|
const dbTableEntryArray = dbTableEntry.split("-");
|
|
const [db_slug, table_slug] = dbTableEntryArray;
|
|
const newEntry = await addDbEntry({
|
|
dbFullName: "datasquirel",
|
|
tableName: "delegated_user_tables",
|
|
data: {
|
|
delegated_user_id: user.id,
|
|
root_user_id: invite,
|
|
database: db_slug,
|
|
table: table_slug,
|
|
priviledge: priviledge
|
|
}
|
|
});
|
|
}
|
|
}
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
}
|
|
// @ts-ignore
|
|
const inviteAccepted = await DB_HANDLER(`UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?`, [
|
|
invite,
|
|
email
|
|
]);
|
|
}
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
} catch (/** @type {any} */ error) {
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
serverError({
|
|
component: "addAdminUserOnLogin",
|
|
message: error.message,
|
|
user: user
|
|
});
|
|
}
|
|
}; ////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
/***/ }),
|
|
|
|
/***/ 7857:
|
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
|
|
// @ts-check
|
|
/**
|
|
* Imports: Handle imports
|
|
*/
|
|
const encrypt = __webpack_require__(2380);
|
|
const sanitizeHtml = __webpack_require__(6109);
|
|
const sanitizeHtmlOptions = __webpack_require__(6704);
|
|
const updateDb = __webpack_require__(5851);
|
|
const updateDbEntry = __webpack_require__(5851);
|
|
const _ = __webpack_require__(6517);
|
|
const DB_HANDLER = __webpack_require__(9395);
|
|
const DSQL_USER_DB_HANDLER = __webpack_require__(8682);
|
|
/**
|
|
* Add a db Entry Function
|
|
* ==============================================================================
|
|
* @description Description
|
|
* @async
|
|
*
|
|
* @param {object} params - An object containing the function parameters.
|
|
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
|
* or "Dsql User". Defaults to "Master"
|
|
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
|
* "Read only" or "Full Access"? Defaults to "Read Only"
|
|
* @param {string} [params.dbFullName] - Database full name
|
|
* @param {string} params.tableName - Table name
|
|
* @param {any} params.data - Data to add
|
|
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
|
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
|
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
|
* @param {boolean} [params.update] - Update this row if it exists
|
|
* @param {string} [params.encryptionKey] - Update this row if it exists
|
|
* @param {string} [params.encryptionSalt] - Update this row if it exists
|
|
*
|
|
* @returns {Promise<any>}
|
|
*/ async function addDbEntry({ dbContext , paradigm , dbFullName , tableName , data , tableSchema , duplicateColumnName , duplicateColumnValue , update , encryptionKey , encryptionSalt , }) {
|
|
/**
|
|
* Initialize variables
|
|
*/ const isMaster = dbContext?.match(/dsql.user/i) ? false : dbFullName && !dbFullName.match(/^datasquirel$/) ? false : true;
|
|
/** @type { any } */ const dbHandler = isMaster ? DB_HANDLER : DSQL_USER_DB_HANDLER;
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
if (data?.["date_created_timestamp"]) delete data["date_created_timestamp"];
|
|
if (data?.["date_updated_timestamp"]) delete data["date_updated_timestamp"];
|
|
if (data?.["date_updated"]) delete data["date_updated"];
|
|
if (data?.["date_updated_code"]) delete data["date_updated_code"];
|
|
if (data?.["date_created"]) delete data["date_created"];
|
|
if (data?.["date_created_code"]) delete data["date_created_code"];
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Handle function logic
|
|
*/ if (duplicateColumnName && typeof duplicateColumnName === "string") {
|
|
const duplicateValue = isMaster ? await dbHandler(`SELECT * FROM \`${tableName}\` WHERE \`${duplicateColumnName}\`=?`, [
|
|
duplicateColumnValue
|
|
]) : await dbHandler({
|
|
paradigm: "Read Only",
|
|
database: dbFullName,
|
|
queryString: `SELECT * FROM \`${tableName}\` WHERE \`${duplicateColumnName}\`=?`,
|
|
queryValues: [
|
|
duplicateColumnValue
|
|
]
|
|
});
|
|
if (duplicateValue?.[0] && !update) {
|
|
return null;
|
|
} else if (duplicateValue && duplicateValue[0] && update) {
|
|
return await updateDbEntry({
|
|
dbContext,
|
|
paradigm,
|
|
dbFullName,
|
|
tableName,
|
|
data,
|
|
tableSchema,
|
|
encryptionKey,
|
|
encryptionSalt,
|
|
identifierColumnName: duplicateColumnName,
|
|
identifierValue: duplicateColumnValue || ""
|
|
});
|
|
}
|
|
}
|
|
/**
|
|
* Declare variables
|
|
*
|
|
* @description Declare "results" variable
|
|
*/ const dataKeys = Object.keys(data);
|
|
let insertKeysArray = [];
|
|
let insertValuesArray = [];
|
|
for(let i = 0; i < dataKeys.length; i++){
|
|
try {
|
|
const dataKey = dataKeys[i];
|
|
// @ts-ignore
|
|
let value = data?.[dataKey];
|
|
const targetFieldSchemaArray = tableSchema ? tableSchema?.fields?.filter((field)=>field.fieldName == dataKey) : null;
|
|
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null;
|
|
if (value == null || value == undefined) continue;
|
|
if (targetFieldSchema?.dataType?.match(/int$/i) && typeof value == "string" && !value?.match(/./)) continue;
|
|
if (targetFieldSchema?.encrypted) {
|
|
value = encrypt(value, encryptionKey, encryptionSalt);
|
|
console.log("DSQL: Encrypted value =>", value);
|
|
}
|
|
if (targetFieldSchema?.richText) {
|
|
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
|
}
|
|
if (targetFieldSchema?.pattern) {
|
|
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
|
|
if (!pattern.test(value)) {
|
|
console.log("DSQL: Pattern not matched =>", value);
|
|
value = "";
|
|
}
|
|
}
|
|
insertKeysArray.push("`" + dataKey + "`");
|
|
if (typeof value === "object") {
|
|
value = JSON.stringify(value);
|
|
}
|
|
if (typeof value == "number") {
|
|
insertValuesArray.push(String(value));
|
|
} else {
|
|
insertValuesArray.push(value);
|
|
}
|
|
} catch (/** @type {any} */ error) {
|
|
console.log("DSQL: Error in parsing data keys =>", error.message);
|
|
continue;
|
|
}
|
|
}
|
|
////////////////////////////////////////
|
|
if (!data?.["date_created"]) {
|
|
insertKeysArray.push("`date_created`");
|
|
insertValuesArray.push(Date());
|
|
}
|
|
if (!data?.["date_created_code"]) {
|
|
insertKeysArray.push("`date_created_code`");
|
|
insertValuesArray.push(Date.now());
|
|
}
|
|
////////////////////////////////////////
|
|
if (!data?.["date_updated"]) {
|
|
insertKeysArray.push("`date_updated`");
|
|
insertValuesArray.push(Date());
|
|
}
|
|
if (!data?.["date_updated_code"]) {
|
|
insertKeysArray.push("`date_updated_code`");
|
|
insertValuesArray.push(Date.now());
|
|
}
|
|
////////////////////////////////////////
|
|
const query = `INSERT INTO \`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.map(()=>"?").join(",")})`;
|
|
const queryValuesArray = insertValuesArray;
|
|
const newInsert = isMaster ? await dbHandler(query, queryValuesArray) : await dbHandler({
|
|
paradigm,
|
|
database: dbFullName,
|
|
queryString: query,
|
|
queryValues: queryValuesArray
|
|
});
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Return statement
|
|
*/ return newInsert;
|
|
}
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
module.exports = addDbEntry;
|
|
|
|
|
|
/***/ }),
|
|
|
|
/***/ 5851:
|
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
|
|
// @ts-check
|
|
/**
|
|
* Imports: Handle imports
|
|
*/
|
|
const encrypt = __webpack_require__(2380);
|
|
const sanitizeHtml = __webpack_require__(6109);
|
|
const sanitizeHtmlOptions = __webpack_require__(6704);
|
|
const DB_HANDLER = __webpack_require__(9395);
|
|
const DSQL_USER_DB_HANDLER = __webpack_require__(8682);
|
|
/**
|
|
* Update DB Function
|
|
* ==============================================================================
|
|
* @description Description
|
|
* @async
|
|
*
|
|
* @param {object} params - An object containing the function parameters.
|
|
* @param {("Master" | "Dsql User")} [params.dbContext] - What is the database context? "Master"
|
|
* or "Dsql User". Defaults to "Master"
|
|
* @param {("Read Only" | "Full Access")} [params.paradigm] - What is the paradigm for "Dsql User"?
|
|
* "Read only" or "Full Access"? Defaults to "Read Only"
|
|
* @param {string} [params.dbFullName] - Database full name
|
|
* @param {string} params.tableName - Table name
|
|
* @param {string} [params.encryptionKey]
|
|
* @param {string} [params.encryptionSalt]
|
|
* @param {any} params.data - Data to add
|
|
* @param {import("../../../types").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
|
* @param {string} params.identifierColumnName - Update row identifier column name
|
|
* @param {string | number} params.identifierValue - Update row identifier column value
|
|
*
|
|
* @returns {Promise<object|null>}
|
|
*/ async function updateDbEntry({ dbContext , paradigm , dbFullName , tableName , data , tableSchema , identifierColumnName , identifierValue , encryptionKey , encryptionSalt , }) {
|
|
/**
|
|
* Check if data is valid
|
|
*/ if (!data || !Object.keys(data).length) return null;
|
|
const isMaster = dbContext?.match(/dsql.user/i) ? false : dbFullName && !dbFullName.match(/^datasquirel$/) ? false : true;
|
|
/** @type {(a1:any, a2?:any)=> any } */ const dbHandler = isMaster ? DB_HANDLER : DSQL_USER_DB_HANDLER;
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Declare variables
|
|
*
|
|
* @description Declare "results" variable
|
|
*/ const dataKeys = Object.keys(data);
|
|
let updateKeyValueArray = [];
|
|
let updateValues = [];
|
|
for(let i = 0; i < dataKeys.length; i++){
|
|
try {
|
|
const dataKey = dataKeys[i];
|
|
// @ts-ignore
|
|
let value = data[dataKey];
|
|
const targetFieldSchemaArray = tableSchema ? tableSchema?.fields?.filter((field)=>field.fieldName === dataKey) : null;
|
|
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null;
|
|
if (value == null || value == undefined) continue;
|
|
if (targetFieldSchema?.richText) {
|
|
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
|
}
|
|
if (targetFieldSchema?.encrypted) {
|
|
value = encrypt(value, encryptionKey, encryptionSalt);
|
|
}
|
|
if (typeof value === "object") {
|
|
value = JSON.stringify(value);
|
|
}
|
|
if (targetFieldSchema?.pattern) {
|
|
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
|
|
if (!pattern.test(value)) {
|
|
console.log("DSQL: Pattern not matched =>", value);
|
|
value = "";
|
|
}
|
|
}
|
|
if (typeof value === "string" && value.match(/^null$/i)) {
|
|
value = {
|
|
toSqlString: function() {
|
|
return "NULL";
|
|
}
|
|
};
|
|
}
|
|
if (typeof value === "string" && !value.match(/./i)) {
|
|
value = {
|
|
toSqlString: function() {
|
|
return "NULL";
|
|
}
|
|
};
|
|
}
|
|
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
|
if (typeof value == "number") {
|
|
updateValues.push(String(value));
|
|
} else {
|
|
updateValues.push(value);
|
|
}
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
} catch (/** @type {any} */ error) {
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
console.log("DSQL: Error in parsing data keys in update function =>", error.message);
|
|
continue;
|
|
}
|
|
}
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
updateKeyValueArray.push(`date_updated='${Date()}'`);
|
|
updateKeyValueArray.push(`date_updated_code='${Date.now()}'`);
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
const query = `UPDATE ${tableName} SET ${updateKeyValueArray.join(",")} WHERE \`${identifierColumnName}\`=?`;
|
|
updateValues.push(identifierValue);
|
|
const updatedEntry = isMaster ? await dbHandler(query, updateValues) : await dbHandler({
|
|
paradigm,
|
|
database: dbFullName,
|
|
queryString: query,
|
|
queryValues: updateValues
|
|
});
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Return statement
|
|
*/ return updatedEntry;
|
|
}
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
module.exports = updateDbEntry;
|
|
|
|
|
|
/***/ }),
|
|
|
|
/***/ 2380:
|
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
|
|
// @ts-check
|
|
|
|
const { scryptSync , createCipheriv } = __webpack_require__(6113);
|
|
const { Buffer } = __webpack_require__(4300);
|
|
const serverError = __webpack_require__(7023);
|
|
/**
|
|
* @async
|
|
* @param {string} data
|
|
* @param {string} [encryptionKey]
|
|
* @param {string} [encryptionSalt]
|
|
* @returns {string | null}
|
|
*/ const encrypt = (data, encryptionKey, encryptionSalt)=>{
|
|
const algorithm = "aes-192-cbc";
|
|
const password = encryptionKey ? encryptionKey : process.env.DSQL_ENCRYPTION_PASSWORD || "";
|
|
/** ********************* Generate key */ const salt = encryptionSalt ? encryptionSalt : process.env.DSQL_ENCRYPTION_SALT || "";
|
|
let key = scryptSync(password, salt, 24);
|
|
let iv = Buffer.alloc(16, 0);
|
|
// @ts-ignore
|
|
const cipher = createCipheriv(algorithm, key, iv);
|
|
/** ********************* Encrypt data */ try {
|
|
let encrypted = cipher.update(data, "utf8", "hex");
|
|
encrypted += cipher.final("hex");
|
|
return encrypted;
|
|
} catch (/** @type {any} */ error) {
|
|
serverError({
|
|
component: "encrypt",
|
|
message: error.message
|
|
});
|
|
return null;
|
|
}
|
|
};
|
|
module.exports = encrypt;
|
|
|
|
|
|
/***/ }),
|
|
|
|
/***/ 6704:
|
|
/***/ ((module) => {
|
|
|
|
// @ts-check
|
|
|
|
const sanitizeHtmlOptions = {
|
|
allowedTags: [
|
|
"b",
|
|
"i",
|
|
"em",
|
|
"strong",
|
|
"a",
|
|
"p",
|
|
"span",
|
|
"ul",
|
|
"ol",
|
|
"li",
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6",
|
|
"img",
|
|
"div",
|
|
"button",
|
|
"pre",
|
|
"code",
|
|
"br"
|
|
],
|
|
allowedAttributes: {
|
|
a: [
|
|
"href"
|
|
],
|
|
img: [
|
|
"src",
|
|
"alt",
|
|
"width",
|
|
"height",
|
|
"class",
|
|
"style"
|
|
],
|
|
"*": [
|
|
"style",
|
|
"class"
|
|
]
|
|
}
|
|
};
|
|
module.exports = sanitizeHtmlOptions;
|
|
|
|
|
|
/***/ }),
|
|
|
|
/***/ 8214:
|
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
|
|
// ESM COMPAT FLAG
|
|
__webpack_require__.r(__webpack_exports__);
|
|
|
|
// EXPORTS
|
|
__webpack_require__.d(__webpack_exports__, {
|
|
"CreateAccountContext": () => (/* binding */ CreateAccountContext),
|
|
"default": () => (/* binding */ CreateAccount),
|
|
"getServerSideProps": () => (/* binding */ getServerSideProps)
|
|
});
|
|
|
|
// EXTERNAL MODULE: external "react/jsx-runtime"
|
|
var jsx_runtime_ = __webpack_require__(997);
|
|
// EXTERNAL MODULE: external "react"
|
|
var external_react_ = __webpack_require__(6689);
|
|
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
|
|
// EXTERNAL MODULE: ./layouts/GeneralLayout.jsx + 1 modules
|
|
var GeneralLayout = __webpack_require__(6217);
|
|
// EXTERNAL MODULE: ./components/general/PageHeadTags.jsx
|
|
var PageHeadTags = __webpack_require__(4097);
|
|
// EXTERNAL MODULE: ./components/pages/create-account/CreateAccountForm.jsx + 1 modules
|
|
var CreateAccountForm = __webpack_require__(5114);
|
|
;// CONCATENATED MODULE: ./components/pages/create-account/Hero.jsx
|
|
// @ts-check
|
|
/**
|
|
* ==============================================================================
|
|
* Imports
|
|
* ==============================================================================
|
|
*/
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* ==============================================================================
|
|
* Main Component { Functional }
|
|
* ==============================================================================
|
|
* @param {Object} props - Server props
|
|
*/ function Hero(props) {
|
|
/**
|
|
* Get Contexts
|
|
*
|
|
* @abstract { React.useContext }
|
|
*/ const { query , invitingUser } = external_react_default().useContext(CreateAccountContext);
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Javascript Variables
|
|
*
|
|
* @abstract Non hook variables and functions
|
|
*/ ////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* React Hooks
|
|
*
|
|
* @abstract { useState, useEffect, useRef, etc ... }
|
|
*/ ////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Function Return
|
|
*
|
|
* @abstract Main Function Return
|
|
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("section", {
|
|
className: "flex-col items-center lg:items-center gap-20 p-0",
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("img", {
|
|
src: "/images/grid.webp",
|
|
alt: "Dotted image background",
|
|
className: "absolute top-0 left-0 w-full h-full object-cover opacity-80 dark:opacity-10 z-0"
|
|
}),
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
|
|
className: "w-full lg:w-1/2 max-w-6xl gap-4 flex-col items-center px-4 py-10 bg-white dark:bg-slate-900 relative z-10",
|
|
children: [
|
|
invitingUser?.first_name && /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
|
|
className: "text-xs bg-emerald-100 rounded-full px-4 py-1 mb-4",
|
|
children: [
|
|
"You have been invited by",
|
|
" ",
|
|
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("b", {
|
|
children: [
|
|
invitingUser.first_name,
|
|
" ",
|
|
invitingUser.last_name,
|
|
" (",
|
|
invitingUser.email,
|
|
")"
|
|
]
|
|
}),
|
|
" ",
|
|
"to manage an account. Please create an account to gain access."
|
|
]
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("h1", {
|
|
className: "m-0 text-center text-2xl",
|
|
children: "Create An Account"
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx(CreateAccountForm/* default */.Z, {
|
|
query: query
|
|
})
|
|
]
|
|
})
|
|
]
|
|
});
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
|
|
|
|
// EXTERNAL MODULE: ./functions/backend/userAuth.js
|
|
var userAuth = __webpack_require__(370);
|
|
var userAuth_default = /*#__PURE__*/__webpack_require__.n(userAuth);
|
|
// EXTERNAL MODULE: ./functions/backend/addAdminUserOnLogin.js
|
|
var addAdminUserOnLogin = __webpack_require__(255);
|
|
var addAdminUserOnLogin_default = /*#__PURE__*/__webpack_require__.n(addAdminUserOnLogin);
|
|
// EXTERNAL MODULE: ./package-shared/utils/backend/global-db/DB_HANDLER.js
|
|
var DB_HANDLER = __webpack_require__(9395);
|
|
var DB_HANDLER_default = /*#__PURE__*/__webpack_require__.n(DB_HANDLER);
|
|
// EXTERNAL MODULE: ./components/general/Logo.jsx
|
|
var Logo = __webpack_require__(4017);
|
|
// EXTERNAL MODULE: ./components/general/LoadingBlock.jsx
|
|
var LoadingBlock = __webpack_require__(5264);
|
|
// EXTERNAL MODULE: ./functions/frontend/fetchApi.js
|
|
var fetchApi = __webpack_require__(6729);
|
|
// EXTERNAL MODULE: ./components/general/LoadingScreen.jsx
|
|
var LoadingScreen = __webpack_require__(6478);
|
|
;// CONCATENATED MODULE: ./pages/create-account.jsx
|
|
// @ts-check
|
|
/**
|
|
* ==============================================================================
|
|
* Imports
|
|
* ==============================================================================
|
|
*/
|
|
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** ****************************************************************************** */ /** @type {import("@/package-shared/types").CreateAccountContextType} */ // @ts-ignore
|
|
const init = {};
|
|
const CreateAccountContext = /*#__PURE__*/ external_react_default().createContext(init);
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* ==============================================================================
|
|
* Main Component { Functional }
|
|
* ==============================================================================
|
|
* @param {Object} props - Server props
|
|
* @param {import("@/package-shared/types").CreateAccountQueryType} props.query
|
|
* @param {any} props.invitingUser
|
|
* @param {any} props.isAuthCookie
|
|
* @param {import("@/package-shared/types").UserType} props.user
|
|
*/ function CreateAccount(props) {
|
|
/**
|
|
* Get Contexts
|
|
*
|
|
* @abstract { React.useContext }
|
|
*/ ////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Javascript Variables
|
|
*
|
|
* @abstract Non hook variables and functions
|
|
*/ const pageTitle = "Create Account | Datasquirel";
|
|
const pageDescription = "Create a FREE account and start storing data.";
|
|
let head = /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
|
|
children: [
|
|
/*#__PURE__*/ jsx_runtime_.jsx("title", {
|
|
children: pageTitle
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx("meta", {
|
|
name: "description",
|
|
content: pageDescription
|
|
}),
|
|
/*#__PURE__*/ jsx_runtime_.jsx(PageHeadTags/* default */.Z, {
|
|
pageTitle: pageTitle,
|
|
pageDescription: pageDescription,
|
|
pagePathname: "/"
|
|
})
|
|
]
|
|
});
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* React Hooks
|
|
*
|
|
* @abstract { useState, useEffect, useRef, etc ... }
|
|
*/ const [user, setUser] = external_react_default().useState(null);
|
|
external_react_default().useEffect(()=>{
|
|
if (props.query?.invite && !props.isAuthCookie) {
|
|
setTimeout(()=>{
|
|
(0,fetchApi/* default */.Z)("/api/addAdminUserUser", {
|
|
method: "POST",
|
|
body: {
|
|
query: props.query
|
|
}
|
|
}, true).then((res)=>{
|
|
window.location.pathname = `/admin/${props.user?.id}/users`;
|
|
});
|
|
// clearCaches()
|
|
// .then(() => {
|
|
// console.log("caches cleared!");
|
|
// })
|
|
// .finally(() => {
|
|
// window.location.reload();
|
|
// });
|
|
}, 1000);
|
|
}
|
|
}, []);
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
if (props.query?.invite) {
|
|
return /*#__PURE__*/ jsx_runtime_.jsx(LoadingScreen/* default */.Z, {});
|
|
}
|
|
/**
|
|
* Function Return
|
|
*
|
|
* @abstract Main Function Return
|
|
*/ return /*#__PURE__*/ jsx_runtime_.jsx(GeneralLayout/* default */.Z, {
|
|
head: head,
|
|
children: /*#__PURE__*/ jsx_runtime_.jsx(CreateAccountContext.Provider, {
|
|
value: {
|
|
user,
|
|
query: props.query,
|
|
invitingUser: props.invitingUser
|
|
},
|
|
children: /*#__PURE__*/ jsx_runtime_.jsx("main", {
|
|
children: /*#__PURE__*/ jsx_runtime_.jsx(Hero, {})
|
|
})
|
|
})
|
|
});
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
}
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* ==============================================================================
|
|
* Server Side Props or Static Props
|
|
* ==============================================================================
|
|
* @type {import("next").GetServerSideProps}
|
|
*/ async function getServerSideProps({ req , res , query }) {
|
|
if (true) {
|
|
return {
|
|
redirect: {
|
|
destination: "/login",
|
|
permanent: false
|
|
}
|
|
};
|
|
}
|
|
/**
|
|
* Page/Site Data Data Fetching
|
|
*
|
|
* @description Fetch data on the server before returning
|
|
*/ const user = await userAuth_default()(req, res);
|
|
if (user?.logged_in_status && !query?.invite) {
|
|
return {
|
|
redirect: {
|
|
destination: "/admin",
|
|
permanent: false
|
|
}
|
|
};
|
|
}
|
|
const isAuthCookie = req.cookies?.datasquirelAuthKey?.match(/./) ? true : false;
|
|
let invitingUser = {};
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Page/Site Data Data Fetching
|
|
*
|
|
* @description Fetch data on the server before returning
|
|
*/ if (query?.email && user?.logged_in_status && user?.email === query.email) {
|
|
console.log("Invitation Received by current logged in user");
|
|
const acceptInvitation = await addAdminUserOnLogin_default()({
|
|
// @ts-ignore
|
|
query,
|
|
user
|
|
});
|
|
return {
|
|
redirect: {
|
|
destination: `/admin/${user?.id}/users`,
|
|
permanent: false
|
|
}
|
|
};
|
|
} else if (query?.email && user?.logged_in_status && user?.email !== query.email) {
|
|
console.log("Invitation Received but email doesn't match!");
|
|
return {
|
|
redirect: {
|
|
destination: "/logout?login=true&" + Object.keys(query).map((key)=>`${key}=${query[key]}`).join("&"),
|
|
permanent: false
|
|
}
|
|
};
|
|
} else if (query?.invite && !user?.logged_in_status) {
|
|
console.log("Invitation Received but no User Logged In");
|
|
const existingUser = await DB_HANDLER_default()(`SELECT first_name FROM users WHERE email='${query.email}'`);
|
|
if (existingUser && existingUser[0]) {
|
|
return {
|
|
redirect: {
|
|
destination: "/login?" + Object.keys(query).map((key)=>`${key}=${query[key]}`).join("&"),
|
|
permanent: false
|
|
}
|
|
};
|
|
}
|
|
const invitingUserDb = await DB_HANDLER_default()(`SELECT first_name,last_name,email FROM users WHERE id='${query.invite}'`);
|
|
if (invitingUserDb && invitingUserDb[0]) invitingUser = invitingUserDb[0];
|
|
} else {
|
|
// console.log("No Invitation Received!");
|
|
}
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
/**
|
|
* Server props return
|
|
*
|
|
* @description Return data fetched on the server side
|
|
*/ return {
|
|
props: {
|
|
user: user,
|
|
query,
|
|
invitingUser,
|
|
isAuthCookie
|
|
}
|
|
};
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
////////////////////////////////////////
|
|
}
|
|
|
|
|
|
/***/ }),
|
|
|
|
/***/ 6843:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("@mui/icons-material/ContentCopy");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 386:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("@mui/icons-material/CottageTwoTone");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 5557:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("@mui/icons-material/MenuBookTwoTone");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 9174:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("@mui/material/Snackbar");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 9538:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("datasquirel");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 6517:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("lodash");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 2423:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("lucide-react");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 968:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("next/head");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 6689:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("react");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 997:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("react/jsx-runtime");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 6109:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("sanitize-html");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 2261:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("serverless-mysql");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 4300:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("buffer");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 6113:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("crypto");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 7147:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("fs");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 3685:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("http");
|
|
|
|
/***/ }),
|
|
|
|
/***/ 1017:
|
|
/***/ ((module) => {
|
|
|
|
module.exports = require("path");
|
|
|
|
/***/ })
|
|
|
|
};
|
|
;
|
|
|
|
// load runtime
|
|
var __webpack_require__ = require("../webpack-runtime.js");
|
|
__webpack_require__.C(exports);
|
|
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
|
var __webpack_exports__ = __webpack_require__.X(0, [4017,8313,5264,6729,5449,913,4480,370,9360,6217,4097,7023,8682,2317,7037,8374,5114,6478], () => (__webpack_exec__(8214)));
|
|
module.exports = __webpack_exports__;
|
|
|
|
})(); |