Updates
This commit is contained in:
+1
-1
@@ -2,4 +2,4 @@ import { APILoginFunctionParams, APILoginFunctionReturn } from "../../../types";
|
||||
/**
|
||||
* # API Login
|
||||
*/
|
||||
export default function apiLoginUser({ encryptionKey, email, username, password, database, additionalFields, email_login, email_login_code, email_login_field, token, skipPassword, social, useLocal, }: APILoginFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
export default function apiLoginUser({ encryptionKey, email, username, password, database, additionalFields, email_login, email_login_code, email_login_field, token, skipPassword, social, useLocal, dbUserId, }: APILoginFunctionParams): Promise<APILoginFunctionReturn>;
|
||||
|
||||
+4
-4
@@ -13,14 +13,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = apiLoginUser;
|
||||
const grab_db_full_name_1 = __importDefault(require("../../../utils/grab-db-full-name"));
|
||||
const varDatabaseDbHandler_1 = __importDefault(require("../../backend/varDatabaseDbHandler"));
|
||||
const hashPassword_1 = __importDefault(require("../../dsql/hashPassword"));
|
||||
/**
|
||||
* # API Login
|
||||
*/
|
||||
function apiLoginUser(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ encryptionKey, email, username, password, database, additionalFields, email_login, email_login_code, email_login_field, token, skipPassword, social, useLocal, }) {
|
||||
const dbFullName = database.replace(/[^a-z0-9_]/g, "");
|
||||
return __awaiter(this, arguments, void 0, function* ({ encryptionKey, email, username, password, database, additionalFields, email_login, email_login_code, email_login_field, token, skipPassword, social, useLocal, dbUserId, }) {
|
||||
const dbFullName = (0, grab_db_full_name_1.default)({ dbName: database, userId: dbUserId });
|
||||
/**
|
||||
* Check input validity
|
||||
*
|
||||
@@ -45,14 +46,13 @@ function apiLoginUser(_a) {
|
||||
password: password,
|
||||
})
|
||||
: null;
|
||||
console.log("Finding DSQL User ...");
|
||||
console.log(`Logging in: Checking for Existing user in ${dbFullName} database.`);
|
||||
let foundUser = yield (0, varDatabaseDbHandler_1.default)({
|
||||
queryString: `SELECT * FROM ${dbFullName}.users WHERE email = ? OR username = ?`,
|
||||
queryValuesArray: [email, username],
|
||||
database: dbFullName,
|
||||
useLocal,
|
||||
});
|
||||
console.log("foundUser", foundUser);
|
||||
if ((!foundUser || !foundUser[0]) && !social)
|
||||
return {
|
||||
success: false,
|
||||
|
||||
Vendored
+2
@@ -143,6 +143,7 @@ export interface PackageUserLoginRequestBody {
|
||||
social?: boolean;
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
skipPassword?: boolean;
|
||||
dbUserId: string | number;
|
||||
}
|
||||
export interface PackageUserLoginLocalBody {
|
||||
payload: any;
|
||||
@@ -1026,6 +1027,7 @@ export type APILoginFunctionParams = {
|
||||
skipPassword?: boolean;
|
||||
social?: boolean;
|
||||
useLocal?: boolean;
|
||||
dbUserId?: number | string;
|
||||
};
|
||||
export type APILoginFunctionReturn = {
|
||||
success: boolean;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
type Param = {
|
||||
dbName: string;
|
||||
userId?: string | number;
|
||||
};
|
||||
/**
|
||||
* # Grab Database Full Name
|
||||
*/
|
||||
export default function grabDbFullName({ dbName, userId }: Param): string;
|
||||
export {};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabDbFullName;
|
||||
/**
|
||||
* # Grab Database Full Name
|
||||
*/
|
||||
function grabDbFullName({ dbName, userId }) {
|
||||
const sanitizedName = dbName.replace(/[^a-z0-9\_]/g, "");
|
||||
const cleanedDbName = sanitizedName.replace(/datasquirel_user_\d+_/, "");
|
||||
if (!userId)
|
||||
return cleanedDbName;
|
||||
const dbNamePrefix = `datasquirel_user_${userId}_`;
|
||||
return dbNamePrefix + cleanedDbName;
|
||||
}
|
||||
Vendored
+2
-1
@@ -23,9 +23,10 @@ type Param = {
|
||||
useLocal?: boolean;
|
||||
skipWriteAuthFile?: boolean;
|
||||
apiUserID?: string | number;
|
||||
dbUserId?: string | number;
|
||||
};
|
||||
/**
|
||||
* # Login A user
|
||||
*/
|
||||
export default function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, useLocal, apiUserID, skipWriteAuthFile, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export default function loginUser({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, useLocal, apiUserID, skipWriteAuthFile, dbUserId, }: Param): Promise<APILoginFunctionReturn>;
|
||||
export {};
|
||||
|
||||
Vendored
+4
-16
@@ -24,7 +24,7 @@ const write_auth_files_1 = require("../package-shared/functions/backend/auth/wri
|
||||
* # Login A user
|
||||
*/
|
||||
function loginUser(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, useLocal, apiUserID, skipWriteAuthFile, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ key, payload, database, additionalFields, response, encryptionKey, encryptionSalt, email_login, email_login_code, temp_code_field, token, user_id, skipPassword, useLocal, apiUserID, skipWriteAuthFile, dbUserId, }) {
|
||||
var _b;
|
||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@@ -101,18 +101,11 @@ function loginUser(_a) {
|
||||
email_login_field: emailLoginTempCodeFieldName,
|
||||
token,
|
||||
useLocal,
|
||||
dbUserId,
|
||||
});
|
||||
}
|
||||
else {
|
||||
/**
|
||||
* Make https request
|
||||
*
|
||||
* @description make a request to datasquirel.com
|
||||
*
|
||||
* @type {{ success: boolean, payload: import("../package-shared/types").DATASQUIREL_LoggedInUser | null, userId?: number, msg?: string }}
|
||||
*/
|
||||
httpResponse = yield new Promise((resolve, reject) => {
|
||||
/** @type {import("../package-shared/types").PackageUserLoginRequestBody} */
|
||||
const reqPayload = {
|
||||
encryptionKey: finalEncryptionKey,
|
||||
payload,
|
||||
@@ -123,6 +116,7 @@ function loginUser(_a) {
|
||||
email_login_field: emailLoginTempCodeFieldName,
|
||||
token,
|
||||
skipPassword: skipPassword,
|
||||
dbUserId: dbUserId || 0,
|
||||
};
|
||||
const reqPayloadJSON = JSON.stringify(reqPayload);
|
||||
const httpsRequest = scheme.request({
|
||||
@@ -137,13 +131,7 @@ function loginUser(_a) {
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/${user_id || grabedHostNames.user_id}/login-user`,
|
||||
},
|
||||
/**
|
||||
* Callback Function
|
||||
*
|
||||
* @description https request callback
|
||||
*/
|
||||
(res) => {
|
||||
}, (res) => {
|
||||
var str = "";
|
||||
res.on("data", function (chunk) {
|
||||
str += chunk;
|
||||
|
||||
Reference in New Issue
Block a user