dsql-admin/dsql-app/.local_dist/server/chunks/4385.js

16 lines
11 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
"use strict";exports.id=4385,exports.ids=[4385],exports.modules={14385:(e,t,a)=>{let s=a(29021),r=a(44767),i=a(59474),{ServerResponse:n}=a(81630),l=a(33873),o=a(5194),u=a(57638),d=a(20503),c=a(47670),m=a(31341),_=a(44900);async function p({user:e,social_platform:t,res:a,invitation:s,database:i,additionalFields:n,useLocal:l}){let o=`SELECT * FROM users WHERE email='${e.email}' AND social_id='${e.social_id}' AND social_platform='${t}'`,c=l?await _(o):await u({database:i||"datasquirel",queryString:o});if(!c?.[0])return{success:!1,user:null};let p=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),g={id:c[0].id,type:c[0].type||"",stripe_id:c[0].stripe_id||"",first_name:c[0].first_name,last_name:c[0].last_name,username:c[0].username,email:c[0].email,social_id:c[0].social_id,image:c[0].image,image_thumbnail:c[0].image_thumbnail,verification_status:c[0].verification_status,social_login:c[0].social_login,social_platform:c[0].social_platform,csrf_k:p,logged_in_status:!0,date:Date.now()};n&&Object.keys(n).length>0&&Object.keys(n).forEach(e=>{g[e]=c[0][e]});let E=d({data:JSON.stringify(g)}),{keyCookieName:S,csrfCookieName:f}=m();return a?.setHeader&&a.setHeader("Set-Cookie",[`${S}=${E};samesite=strict;path=/;HttpOnly=true;Secure=true`,`${f}=${p};samesite=strict;path=/;HttpOnly=true`]),s&&(!i||i?.match(/^datasquirel$/))&&r({query:s,user:g}),{success:!0,user:g}}e.exports=async function({database:e,social_id:t,email:a,social_platform:r,payload:n,res:m,invitation:g,supEmail:E,additionalFields:S,useLocal:f}){try{let y="SELECT * FROM users WHERE social_id = ? AND social_login='1' AND social_platform = ? ",D=[t.toString(),r],b=f?await _(y,D):await u({database:e||"datasquirel",queryString:y,queryValuesArray:D});if(b&&b[0])return await p({user:b[0],social_platform:r,res:m,invitation:g,database:e,additionalFields:S,useLocal:f});let h=a||E||null;if(!h)return{success:!1,user:null,msg:"No Email Present",social_id:t,social_platform:r,payload:n};let R=`SELECT * FROM users WHERE email='${h}'`,v=f?await _(R):await u({database:e||"datasquirel",queryString:R});if(v&&v[0])return{success:!1,user:null,msg:"This Email is already taken",alert:!0};let A=`SELECT * FROM users WHERE email='${h}' AND social_login='1' AND social_platform='${r}' AND social_id='${t}'`,L=f?await _(A):await u({database:e||"datasquirel",queryString:A});if(L&&L[0])return await p({user:n,social_platform:r,res:m,invitation:g,database:e,additionalFields:S,useLocal:f});let N=d({data:t.toString()}),O={social_login:"1",verification_status:E?"0":"1",password:N};Object.keys(n).forEach(e=>{O[e]=n[e]});let w=await c({dbContext:e?"Dsql User":void 0,paradigm:e?"Full Access":void 0,dbFullName:e||"datasquirel",tableName:"users",duplicateColumnName:"email",duplicateColumnValue:h,data:{...O,email:h},useLocal:f});if(!w?.insertId)return console.log("Social User Failed to insert in 'handleSocialDb.js' backend function =>",w),{success:!1,user:null,msg:"Social User Failed to insert in 'handleSocialDb.js' backend function => ",newUser:w};{e||await o({userId:w.insertId,useLocal:f});let t=`SELECT * FROM users WHERE id='${w.insertId}'`,a=f?await _(t):await u({database:e||"datasquirel",queryString:t});if(!a||!a[0])return{success:!1,user:null,msg:"User Insertion Failed!"};if(E&&e?.match(/^datasquirel$/)){let e=d({data:JSON.stringify({id:w.insertId,email:E,dateCode:Date.now()})});i({to:E,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 n=process.env.DSQL_STATIC_SERVER_DIR;if(!n)return console.log("Static File ENV not Found!"),null;if(!e||e?.match(/^datasquirel$/)){let e=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${w.insertId}`,t=l.join(n,`images/user-images/user-${w.insertId}`);s.mkdirSync(e),s.mkdirSync(t),s.writeFileSync(`${e}/main.json`,JSON.stringify([]),"utf8")}return await p({user:a[0],social_platform:r,res:m,invitation:g,database:e,additionalFields:S,useLocal:f})}}catc
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)}`),l&&(r+=`
IP: ${l}`),r+=`
Date: ${n.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)}}},57638:(e,t,a)=>{a(29021);let s=a(6061),r=a(48225),i=a(51348),n=a(21339);e.exports=async function({queryString:e,queryValuesArray:t,database:a,tableSchema:l}){let o;let u=!!a?.match(/^datasquirel$/),d=u?i:n;try{o=e&&t&&Array.isArray(t)&&t[0]?u?await d(e,t):await d({paradigm:"Full Access",database:a,queryString:e,queryValues:t}):u?await d(e):await d({paradigm:"Full Access",database:a,queryString:e})}catch(e){r({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(o&&l)try{let e=o;return await s({unparsedResults:e,tableSchema:l})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",a,e),r({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(o)return o;else return null}},72835:(e,t,a)=>{let{scryptSync:s,createDecipheriv:r}=a(55511),{Buffer:i}=a(79428);e.exports=({encryptedString:e,encryptionKey:t,encryptionSalt:a})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=t||process.env.DSQL_ENCRYPTION_PASSWORD,l=a||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=r("aes-192-cbc",s(n,l,o),i.alloc(16,0));try{let t=u.update(e,"hex","utf8");return t+=u.final("utf8")}catch(t){return console.log("Error in decrypting =>",t.message),e}}},45356:(e,t,a)=>{let s=a(9973),r=a(21580),i=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,charset:"utf8mb4",ssl:r()}});e.exports=function(...e){try{return new Promise((t,a)=>{i.query(...e).then(e=>{i.end(),t(JSON.parse(JSON.stringify(e)))}).catch(e=>{i.end(),t({error:e.message,sql:e.sql})})})}catch(e){return{success:!1,error:e.message}}}}};