16 lines
10 KiB
JavaScript
16 lines
10 KiB
JavaScript
|
"use strict";exports.id=6946,exports.ids=[6946],exports.modules={98968:(e,t,a)=>{a(29021),a(28187);let s=a(77538),r=a(51348),i=a(47670);e.exports=async function({query:e,user:t}){try{let{invite:a,database_access:s,priviledge:l,email:n}=e,o=await r("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[a,n]);if(!o||!o[0])throw Error("No Invitation Found");let u=await r("SELECT first_name,last_name,email FROM users WHERE id=?",[a]);if(u?.[0]){let e=await r("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[a,t.id,n]);if(e?.[0])console.log("User already added");else{i({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:a,invited_user_id:t.id,database_access:s,first_name:t.first_name,last_name:t.last_name,phone:t.phone,email:t.email,username:t.username,user_type:"admin",user_priviledge:l,image:t.image,image_thumbnail:t.image_thumbnail}});let e=await r("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[a,n]);if(await r("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[a,t.id]),e&&e[0]){let s=e[0].db_tables_data.split("|");for(let e=0;e<s.length;e++){let[r,n]=s[e].split("-");await i({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:t.id,root_user_id:a,database:r,table:n,priviledge:l}})}}}await r("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[a,n])}}catch(e){s({component:"addAdminUserOnLogin",message:e.message,user:t})}}},79531:(e,t,a)=>{let s=a(29021),r=a(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:t,text:a,html:i,alias:l}){let n;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let o=(l?.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}}/,i||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let s={};s.from=`"Datasquirel" <${o}>`,s.sender=o,l&&(s["replyTo "]=o),s.to=e,s.subject=t,s.text=a,s.html=u,n=await r.sendMail(s)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return n}},77538:(e,t,a)=>{let s=a(29021),{IncomingMessage:r}=a(81630);e.exports=async function({user:e,message:t,component:a,noMail:r,req:i}){let l=new Date,n=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],t=i.headers["x-real-ip"],a=i.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],r=a||s||t||i.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let r=`🚀 SERVER ERROR ===========================
|
||
|
Error Message: ${t}
|
||
|
Component: ${a}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(r+=`
|
||
|
User Id: ${e?.id}
|
||
|
User Name: ${e?.first_name} ${e?.last_name}
|
||
|
User Email: ${e?.email}`),i?.url&&(r+=`
|
||
|
URL: ${i.url}`),i?.body&&(r+=`
|
||
|
Request Body: ${JSON.stringify(i.body,null,4)}`),n&&(r+=`
|
||
|
IP: ${n}`),r+=`
|
||
|
Date: ${l.toDateString()}
|
||
|
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",r),s.appendFileSync("./.tmp/error.log",`
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},36946:(e,t,a)=>{let s=a(29021),r=a(98968),i=a(79531),{ServerResponse:l}=a(81630),n=a(33873),o=a(5194),u=a(57638),d=a(82703),c=a(47670);async function m({user:e,social_platform:t,res:a,invitation:s,database:i,additionalFields:l}){let n=await u({database:i||"datasquirel",queryString:`SELECT * FROM users WHERE email='${e.email}' AND social_id='${e.social_id}' AND social_platform='${t}'`});if(!n?.[0])return{success:!1,user:null};let o=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),c={id:n[0].id,type:n[0].type||"",stripe_id:n[0].stripe_id||"",first_name:n[0].first_name,last_name:n[0].last_name,username:n[0].username,email:n[0].email,social_id:n[0].social_id,image:n[0].image,image_thumbnail:n[0].image_thumbnail,verification_status:n[0].verification_status,social_login:n[0].social_login,social_platform:n[0].social_platform,csrf_k:o,logged_in_status:!0,date:Date.now()};l&&Object.keys(l).length>0&&Object.keys(l).forEach(e=>{c[e]=n[0][e]});let m=d(JSON.stringify(c));return a?.setHeader&&a.setHeader("Set-Cookie",[`datasquirelAuthKey=${m};samesite=strict;path=/;HttpOnly=true;Secure=true`,`csrf=${o};samesite=strict;path=/;HttpOnly=true`]),s&&(!i||i?.match(/^datasquirel$/))&&r({query:s,user:c}),{success:!0,user:c}}e.exports=async function({database:e,social_id:t,email:a,social_platform:r,payload:l,res:_,invitation:p,supEmail:g,additionalFields:S}){try{let E=await u({database:e||"datasquirel",queryString:"SELECT * FROM users WHERE social_id = ? AND social_login='1' AND social_platform = ? ",queryValuesArray:[t.toString(),r]});if(E&&E[0])return await m({user:E[0],social_platform:r,res:_,invitation:p,database:e,additionalFields:S});let f=a||g||null;if(!f)return{success:!1,user:null,msg:"No Email Present",social_id:t,social_platform:r,payload:l};let y=await u({database:e||"datasquirel",queryString:`SELECT * FROM users WHERE email='${f}'`});if(y&&y[0])return{user:null,msg:"This Email is already taken",alert:!0};let b=await u({database:e||"datasquirel",queryString:`SELECT * FROM users WHERE email='${f}' AND social_login='1' AND social_platform='${r}' AND social_id='${t}'`});if(b&&b[0])return await m({user:l,social_platform:r,res:_,invitation:p,database:e,additionalFields:S});let h=d(t.toString()),D={social_login:"1",verification_status:g?"0":"1",password:h};Object.keys(l).forEach(e=>{D[e]=l[e]});let R=await c({dbContext:e?"Dsql User":void 0,paradigm:e?"Full Access":void 0,dbFullName:e||"datasquirel",tableName:"users",duplicateColumnName:"email",duplicateColumnValue:f,data:{...D,email:f}});if(!R?.insertId)return console.log("Social User Failed to insert in 'handleSocialDb.js' backend function =>",R),{success:!1,user:null,msg:"Social User Failed to insert in 'handleSocialDb.js' backend function => ",newUser:R};{e||await o({userId:R.insertId});let t=await u({database:e||"datasquirel",queryString:`SELECT * FROM users WHERE id='${R.insertId}'`});if(!t||!t[0])return{user:null,msg:"User Insertion Failed!"};if(g&&e?.match(/^datasquirel$/)){let e=d(JSON.stringify({id:R.insertId,email:g,dateCode:Date.now()}));i({to:g,subject:"Verify Email Address",text:"Please click the link to verify your email address",html:s.readFileSync("./email/send-email-verification-link.html","utf8").replace(/{{host}}/,process.env.DSQL_HOST||"").replace(/{{token}}/,e||"")}).then(e=>{})}let a=process.env.DSQL_STATIC_SERVER_DIR;if(!a)return console.log("Static File ENV not Found!"),null;if(!e||e?.match(/^datasquirel$/)){let e=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${R.insertId}`,t=n.join(a,`images/user-images/user-${R.insertId}`);s.mkdirSync(e),s.mkdirSync(t),s.writeFileSync(`${e}/main.json`,JSON.stringify([]),"utf8")}return await m({user:t[0],social_platform:r,res:_,invitation:p,database:e,additionalFields:S})}}catch(e){return console.log("ERROR in 'handleSocialDb.js' backend function =>",e.message),{success:!1,user:null,error:e.message}}return{user:null,msg:"User Login Failed!"}}},5194:(e,t,a)=>{let s=a(47795),r=a(51348),i=a(45356),l=a(82703),n=a(47670);e.exp
|