Updates
This commit is contained in:
@@ -1,310 +1,19 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 6134;
|
||||
exports.ids = [6134];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 9538:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("datasquirel");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2029:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("datasquirel/functions/hashPassword");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6517:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("lodash");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5184:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("nodemailer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9842:
|
||||
/***/ ((module) => {
|
||||
|
||||
// @ts-check
|
||||
/**
|
||||
* Delay async function
|
||||
*
|
||||
* @param {number} [milliseconds]
|
||||
*
|
||||
* @returns {Promise<boolean>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function delay(milliseconds) {
|
||||
await new Promise((resolve, reject)=>{
|
||||
setTimeout(()=>{
|
||||
resolve(true);
|
||||
}, milliseconds || 1000);
|
||||
});
|
||||
return true;
|
||||
}; ////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
"use strict";(()=>{var e={};e.id=3303,e.ids=[3303],e.modules={28187:e=>{e.exports=require("@moduletrace/datasquirel")},43499:e=>{e.exports=require("@moduletrace/datasquirel/functions/hashPassword")},27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},21572:e=>{e.exports=require("nodemailer")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},95122:(e,r,t)=>{t.r(r),t.d(r,{config:()=>A,default:()=>v,routeModule:()=>w});var s={};t.r(s),t.d(s,{default:()=>L});var i=t(89947),a=t(2706),n=t(96762),o=t(51348),l=t.n(o),u=t(98968),d=t.n(u),m=t(77538),_=t.n(m),c=t(79531),p=t.n(c),g=t(91766),f=t.n(g),h=t(43499),S=t.n(h);let E=t(29021),y=t(82703);async function L(e,r){if("POST"===e.method){let t=e.body,s=t.email,i=t.password,a=t.query;if(s.match(/ /))return r.json({user:null,msg:"Invalid Email"});try{let t=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!t)throw Error("loginUser error: process.env.DSQL_USER_LOGIN_KEYS_PATH not present");E.existsSync(t)||E.mkdirSync(t,{recursive:!0});let n=e.headers["x-real-ip"]||e.headers["x-forwarded-for"]||e.connection.remoteAddress,o=process.env.DSQL_HOST||"https://datasquirel.com",u=S()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:i});if(i?.match(/ /)||s?.match(/ /))return r.json({msg:"Failed!",user:null});let m=await l()("SELECT * FROM users WHERE email=? OR username=?",[s,s]);if(!m||!m[0])return r.json({msg:"No user found",user:null});let _=!1;if(m&&m[0]&&(_=u===m[0].password),!_)return await f()(),p()({to:process.env.DSQL_CONTACT_EMAIL,subject:`Failed Login from ${s}`,html:`<h1><u>${s}</u> tried to login with a wrong password</h1><p><b>${s}</b> attempted a login on ${o} from ${n} with a wrong password.</p>`}),r.json({msg:"Wrong Password, Wrong Social Media Credentials",user:null});let c=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),g={id:m[0].id,stripe_id:m[0].stripe_id||"",first_name:m[0].first_name,last_name:m[0].last_name,username:m[0].username,email:m[0].email,social_id:m[0].social_id,image:m[0].image,image_thumbnail:m[0].image_thumbnail,verification_status:m[0].verification_status,social_login:m[0].social_login,social_platform:m[0].social_platform,csrf_k:c,logged_in_status:!0,date:Date.now()},h=y(JSON.stringify(g));r.setHeader("Set-Cookie",[`datasquirelAuthKey=${h};samesite=strict;path=/;HttpOnly=true;Secure=true`,`csrf=${c};samesite=strict;path=/;HttpOnly=true`]),E.appendFile("./.tmp/userLoginLogs.log",`${m[0].first_name} ${m[0].last_name} Logged in from ${m[0].social_login?m[0].social_platform:"Regular Email Login"} at ${Date()}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4150:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2224);
|
||||
/* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(613);
|
||||
/* harmony import */ var _functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6926);
|
||||
/* harmony import */ var _functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _functions_backend_delay__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9842);
|
||||
/* harmony import */ var _functions_backend_delay__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_delay__WEBPACK_IMPORTED_MODULE_4__);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(2029);
|
||||
/* harmony import */ var datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_5__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
`,"utf8",e=>{e&&console.log("Loging log write error")}),E.writeFileSync(`${t}/${c}`,JSON.stringify(g)),a?.invite&&d()({query:a,user:{...g,phone:m[0].phone}}),await f()(),p()({to:process.env.DSQL_CONTACT_EMAIL,subject:`${s} Logged in successfully`,html:`<h1><u>${s}</u> successfully logged in</h1><p><b>${s}</b> successfully logged in on ${o} from ${n} on ${Date().substring(0,16)}.</p>`}),r.json({msg:"User Found",user:{auth:!0,userid:m[0].id,csrf_k:c,stripe_id:m[0].stripe_id||""},userPayload:g})}catch(e){console.log("Login Error =>",e.message),_()({component:"/api/loginUser/main-catch-error",message:e.message,user:{email:s}})}}else r.json({msg:"Oops ..."})}let v=(0,n.M)(s,"default"),A=(0,n.M)(s,"config"),w=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/loginUser",pathname:"/api/loginUser",bundlePath:"",filename:""},userland:s})},98968:(e,r,t)=>{t(29021),t(28187);let s=t(77538),i=t(51348),a=t(47670);e.exports=async function({query:e,user:r}){try{let{invite:t,database_access:s,priviledge:n,email:o}=e,l=await i("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[t,o]);if(!l||!l[0])throw Error("No Invitation Found");let u=await i("SELECT first_name,last_name,email FROM users WHERE id=?",[t]);if(u?.[0]){let e=await i("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[t,r.id,o]);if(e?.[0])console.log("User already added");else{a({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:t,invited_user_id:r.id,database_access:s,first_name:r.first_name,last_name:r.last_name,phone:r.phone,email:r.email,username:r.username,user_type:"admin",user_priviledge:n,image:r.image,image_thumbnail:r.image_thumbnail}});let e=await i("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[t,o]);if(await i("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[t,r.id]),e&&e[0]){let s=e[0].db_tables_data.split("|");for(let e=0;e<s.length;e++){let[i,o]=s[e].split("-");await a({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:t,database:i,table:o,priviledge:n}})}}}await i("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[t,o])}}catch(e){s({component:"addAdminUserOnLogin",message:e.message,user:r})}}},91766:e=>{e.exports=async function(e){return await new Promise((r,t)=>{setTimeout(()=>{r(!0)},e||1e3)}),!0}},79531:(e,r,t)=>{let s=t(29021),i=t(21572).createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});e.exports=async function({to:e,subject:r,text:t,html:a,alias:n}){let o;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let l=(n?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!s.existsSync("./email/index.html"))return;let u=s.readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,a||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let s={};s.from=`"Datasquirel" <${l}>`,s.sender=l,n&&(s["replyTo "]=l),s.to=e,s.subject=r,s.text=t,s.html=u,o=await i.sendMail(s)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return o}},77538:(e,r,t)=>{let s=t(29021),{IncomingMessage:i}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:i,req:a}){let n=new Date,o=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||s||r||a.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let i=`🚀 SERVER ERROR ===========================
|
||||
Error Message: ${r}
|
||||
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(i+=`
|
||||
User Id: ${e?.id}
|
||||
User Name: ${e?.first_name} ${e?.last_name}
|
||||
User Email: ${e?.email}`),a?.url&&(i+=`
|
||||
URL: ${a.url}`),a?.body&&(i+=`
|
||||
Request Body: ${JSON.stringify(a.body,null,4)}`),o&&(i+=`
|
||||
IP: ${o}`),i+=`
|
||||
Date: ${n.toDateString()}
|
||||
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let l=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",i),s.appendFileSync("./.tmp/error.log",`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const encrypt = __webpack_require__(7547);
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
if (req.method === "POST") {
|
||||
/** ********************* Get Page Data */ const sanitizedReqBody = req.body;
|
||||
// let { email, password, query } = reqBody;
|
||||
let email = sanitizedReqBody.email;
|
||||
let password = sanitizedReqBody.password;
|
||||
let query = sanitizedReqBody.query;
|
||||
if (email.match(/ /)) return res.json({
|
||||
user: null,
|
||||
msg: "Invalid Email"
|
||||
});
|
||||
try {
|
||||
const allowedAuthKeysPath = process.env.DSQL_USER_LOGIN_KEYS_PATH;
|
||||
if (!allowedAuthKeysPath) throw new Error("loginUser error: process.env.DSQL_USER_LOGIN_KEYS_PATH not present");
|
||||
if (!fs.existsSync(allowedAuthKeysPath)) {
|
||||
fs.mkdirSync(allowedAuthKeysPath, {
|
||||
recursive: true
|
||||
});
|
||||
}
|
||||
const ip = req.headers["x-real-ip"] || req.headers["x-forwarded-for"] || req.connection.remoteAddress;
|
||||
const site = process.env.DSQL_HOST || "https://datasquirel.com";
|
||||
let hashedPassword = datasquirel_functions_hashPassword__WEBPACK_IMPORTED_MODULE_5___default()({
|
||||
encryptionKey: process.env.DSQL_ENCRYPTION_PASSWORD || "",
|
||||
password: password
|
||||
});
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
if (password?.match(/ /) || email?.match(/ /)) {
|
||||
return res.json({
|
||||
msg: "Failed!",
|
||||
user: null
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
let foundUser = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_0___default()(`SELECT * FROM users WHERE email=? OR username=?`, [
|
||||
email,
|
||||
email
|
||||
]);
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
if (!foundUser || !foundUser[0]) {
|
||||
return res.json({
|
||||
msg: "No user found",
|
||||
user: null
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
let isPasswordCorrect = false;
|
||||
if (foundUser && foundUser[0]) isPasswordCorrect = hashedPassword === foundUser[0].password;
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
if (!isPasswordCorrect) {
|
||||
await _functions_backend_delay__WEBPACK_IMPORTED_MODULE_4___default()();
|
||||
if (true) {
|
||||
_functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
to: process.env.DSQL_CONTACT_EMAIL,
|
||||
subject: `Failed Login from ${email}`,
|
||||
html: `<h1><u>${email}</u> tried to login with a wrong password</h1><p><b>${email}</b> attempted a login on ${site} from ${ip} with a wrong password.</p>`
|
||||
});
|
||||
}
|
||||
return res.json({
|
||||
msg: "Wrong Password, Wrong Social Media Credentials",
|
||||
user: null
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
let csrfKey = Math.random().toString(36).substring(2) + "-" + Math.random().toString(36).substring(2);
|
||||
let userPayload = {
|
||||
id: foundUser[0].id,
|
||||
stripe_id: foundUser[0].stripe_id || "",
|
||||
first_name: foundUser[0].first_name,
|
||||
last_name: foundUser[0].last_name,
|
||||
username: foundUser[0].username,
|
||||
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()
|
||||
};
|
||||
let encryptedPayload = encrypt(JSON.stringify(userPayload));
|
||||
res.setHeader("Set-Cookie", [
|
||||
`datasquirelAuthKey=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
|
||||
`csrf=${csrfKey};samesite=strict;path=/;HttpOnly=true`,
|
||||
]);
|
||||
fs.appendFile("./.tmp/userLoginLogs.log", `${foundUser[0].first_name} ${foundUser[0].last_name} Logged in from ${foundUser[0].social_login ? foundUser[0].social_platform : "Regular Email Login"} at ${Date()} \n\n\n`, "utf8", (err)=>{
|
||||
if (err) console.log(`Loging log write error`);
|
||||
});
|
||||
fs.writeFileSync(`${allowedAuthKeysPath}/${csrfKey}`, JSON.stringify(userPayload));
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
if (query?.invite) {
|
||||
_functions_backend_addAdminUserOnLogin__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
query: query,
|
||||
user: {
|
||||
...userPayload,
|
||||
phone: foundUser[0].phone
|
||||
}
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
await _functions_backend_delay__WEBPACK_IMPORTED_MODULE_4___default()();
|
||||
if (true) {
|
||||
_functions_backend_handleNodemailer__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
to: process.env.DSQL_CONTACT_EMAIL,
|
||||
subject: `${email} Logged in successfully`,
|
||||
html: `<h1><u>${email}</u> successfully logged in</h1><p><b>${email}</b> successfully logged in on ${site} from ${ip} on ${Date().substring(0, 16)}.</p>`
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
/** ********************* Send Response */ res.json({
|
||||
msg: "User Found",
|
||||
user: {
|
||||
auth: true,
|
||||
userid: foundUser[0].id,
|
||||
csrf_k: csrfKey,
|
||||
stripe_id: foundUser[0].stripe_id || ""
|
||||
},
|
||||
userPayload
|
||||
});
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log("Login Error =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
component: "/api/loginUser/main-catch-error",
|
||||
message: error.message,
|
||||
user: {
|
||||
email: email
|
||||
}
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
} else {
|
||||
res.json({
|
||||
msg: "Oops ..."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,3017,3403,7547,5886,5338,6926,613], () => (__webpack_exec__(4150)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4050],()=>t(95122));module.exports=s})();
|
||||
Reference in New Issue
Block a user