Updates
This commit is contained in:
+11
-2
@@ -16,6 +16,7 @@ exports.default = queryDSQLAPI;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||
const serialize_query_1 = __importDefault(require("../../utils/serialize-query"));
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
/**
|
||||
* # Query DSQL API
|
||||
*/
|
||||
@@ -88,7 +89,12 @@ function queryDSQLAPI(_a) {
|
||||
payload: undefined,
|
||||
msg: `An error occurred while parsing the response`,
|
||||
error: error.message,
|
||||
errorData: { requestOptions, grabedHostNames },
|
||||
errorData: {
|
||||
requestOptions,
|
||||
grabedHostNames: lodash_1.default.omit(grabedHostNames, [
|
||||
"scheme",
|
||||
]),
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -108,7 +114,10 @@ function queryDSQLAPI(_a) {
|
||||
payload: undefined,
|
||||
msg: `An error occurred while making the request`,
|
||||
error: err.message,
|
||||
errorData: { requestOptions, grabedHostNames },
|
||||
errorData: {
|
||||
requestOptions,
|
||||
grabedHostNames: lodash_1.default.omit(grabedHostNames, ["scheme"]),
|
||||
},
|
||||
});
|
||||
});
|
||||
if (reqPayload) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { APILoginFunctionReturn, HandleSocialDbFunctionParams } from "../../../types";
|
||||
import { APIResponseObject, HandleSocialDbFunctionParams } from "../../../types";
|
||||
/**
|
||||
* # Handle Social DB
|
||||
*/
|
||||
export default function handleSocialDb({ database, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, apiUserId, }: HandleSocialDbFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
export default function handleSocialDb({ database, email, social_platform, payload, invitation, supEmail, additionalFields, debug, loginOnly, apiUserId, }: HandleSocialDbFunctionParams): Promise<APIResponseObject>;
|
||||
|
||||
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = handleSocialDb;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const handleNodemailer_1 = __importDefault(require("../../backend/handleNodemailer"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const addMariadbUser_1 = __importDefault(require("../../backend/addMariadbUser"));
|
||||
const dbHandler_1 = __importDefault(require("../../backend/dbHandler"));
|
||||
const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
|
||||
@@ -162,26 +161,19 @@ function handleSocialDb(_a) {
|
||||
.replace(/{{token}}/, generatedToken || ""),
|
||||
}).then(() => { });
|
||||
}
|
||||
const { STATIC_ROOT } = (0, grab_dir_names_1.default)();
|
||||
if (!STATIC_ROOT) {
|
||||
console.log("Static File ENV not Found!");
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Static File ENV not Found!",
|
||||
};
|
||||
}
|
||||
const { userPrivateMediaDir, userPublicMediaDir } = (0, grab_dir_names_1.default)({
|
||||
userId: newUser.payload.insertId,
|
||||
});
|
||||
/**
|
||||
* Create new user folder and file
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/
|
||||
if (!database || (database === null || database === void 0 ? void 0 : database.match(/^datasquirel$/))) {
|
||||
let newUserSchemaFolderPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${newUser.payload.insertId}`;
|
||||
let newUserMediaFolderPath = path_1.default.join(STATIC_ROOT, `images/user-images/user-${newUser.payload.insertId}`);
|
||||
fs_1.default.mkdirSync(newUserSchemaFolderPath);
|
||||
fs_1.default.mkdirSync(newUserMediaFolderPath);
|
||||
fs_1.default.writeFileSync(`${newUserSchemaFolderPath}/main.json`, JSON.stringify([]), "utf8");
|
||||
userPublicMediaDir &&
|
||||
fs_1.default.mkdirSync(userPublicMediaDir, { recursive: true });
|
||||
userPrivateMediaDir &&
|
||||
fs_1.default.mkdirSync(userPrivateMediaDir, { recursive: true });
|
||||
}
|
||||
return yield (0, loginSocialUser_1.default)({
|
||||
user: newUserQueried[0],
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { APILoginFunctionReturn } from "../../../types";
|
||||
import { APIResponseObject } from "../../../types";
|
||||
type Param = {
|
||||
user: {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
social_id: string | number;
|
||||
};
|
||||
social_platform: string;
|
||||
invitation?: any;
|
||||
@@ -18,5 +15,5 @@ type Param = {
|
||||
* @description This function logs in the user after 'handleSocialDb' function finishes
|
||||
* the user creation or confirmation process
|
||||
*/
|
||||
export default function loginSocialUser({ user, social_platform, invitation, database, additionalFields, debug, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export default function loginSocialUser({ user, social_platform, invitation, database, additionalFields, debug, }: Param): Promise<APIResponseObject>;
|
||||
export {};
|
||||
|
||||
@@ -13,8 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = loginSocialUser;
|
||||
const addAdminUserOnLogin_1 = __importDefault(require("../../backend/addAdminUserOnLogin"));
|
||||
const dbHandler_1 = __importDefault(require("../../backend/dbHandler"));
|
||||
const login_user_1 = __importDefault(require("../../../actions/users/login-user"));
|
||||
/**
|
||||
* Function to login social user
|
||||
* ==============================================================================
|
||||
@@ -24,57 +23,15 @@ const dbHandler_1 = __importDefault(require("../../backend/dbHandler"));
|
||||
function loginSocialUser(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ user, social_platform, invitation, database, additionalFields, debug, }) {
|
||||
const finalDbName = database ? database : "datasquirel";
|
||||
const dbAppend = database ? `\`${finalDbName}\`.` : "";
|
||||
const foundUserQuery = `SELECT * FROM ${dbAppend}\`users\` WHERE email=?`;
|
||||
const foundUserValues = [user.email];
|
||||
const foundUser = (yield (0, dbHandler_1.default)({
|
||||
query: foundUserQuery,
|
||||
values: foundUserValues,
|
||||
let userPayload = yield (0, login_user_1.default)({
|
||||
database: finalDbName,
|
||||
}));
|
||||
if (!(foundUser === null || foundUser === void 0 ? void 0 : foundUser[0]))
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Couldn't find Social User.",
|
||||
};
|
||||
let csrfKey = Math.random().toString(36).substring(2) +
|
||||
"-" +
|
||||
Math.random().toString(36).substring(2);
|
||||
let userPayload = {
|
||||
id: foundUser[0].id,
|
||||
uuid: foundUser[0].uuid,
|
||||
first_name: foundUser[0].first_name,
|
||||
last_name: foundUser[0].last_name,
|
||||
username: foundUser[0].username,
|
||||
user_type: foundUser[0].user_type,
|
||||
email: foundUser[0].email,
|
||||
social_id: foundUser[0].social_id,
|
||||
image: foundUser[0].image,
|
||||
image_thumbnail: foundUser[0].image_thumbnail,
|
||||
verification_status: foundUser[0].verification_status,
|
||||
social_login: foundUser[0].social_login,
|
||||
social_platform: foundUser[0].social_platform,
|
||||
csrf_k: csrfKey,
|
||||
logged_in_status: true,
|
||||
date: Date.now(),
|
||||
};
|
||||
if (additionalFields === null || additionalFields === void 0 ? void 0 : additionalFields[0]) {
|
||||
additionalFields.forEach((key) => {
|
||||
userPayload[key] = foundUser[0][key];
|
||||
});
|
||||
}
|
||||
if (invitation && (!database || (database === null || database === void 0 ? void 0 : database.match(/^datasquirel$/)))) {
|
||||
(0, addAdminUserOnLogin_1.default)({
|
||||
query: invitation,
|
||||
user: userPayload,
|
||||
});
|
||||
}
|
||||
let result = {
|
||||
success: true,
|
||||
payload: userPayload,
|
||||
csrf: csrfKey,
|
||||
};
|
||||
return result;
|
||||
payload: { email: user.email },
|
||||
skipPassword: true,
|
||||
skipWriteAuthFile: true,
|
||||
additionalFields,
|
||||
debug,
|
||||
useLocal: true,
|
||||
});
|
||||
return userPayload;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { APIGoogleLoginFunctionParams, APILoginFunctionReturn } from "../../../../types";
|
||||
import { APIGoogleLoginFunctionParams } from "../../../../types";
|
||||
import { APIResponseObject } from "../../../../types";
|
||||
/**
|
||||
* # API google login
|
||||
*/
|
||||
export default function apiGoogleLogin({ token, database, additionalFields, additionalData, debug, loginOnly, apiUserId, }: APIGoogleLoginFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
export default function apiGoogleLogin({ token, database, additionalFields, additionalData, debug, loginOnly, apiUserId, }: APIGoogleLoginFunctionParams): Promise<APIResponseObject>;
|
||||
|
||||
Reference in New Issue
Block a user