"use strict";(()=>{var e={};e.id=3812,e.ids=[3812],e.modules={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")},21110:(e,s,a)=>{a.r(s),a.d(s,{config:()=>g,default:()=>S,routeModule:()=>b});var t={};a.r(t),a.d(t,{default:()=>h});var r=a(89947),i=a(2706),n=a(96762),l=a(79531),d=a.n(l),u=a(43499),o=a.n(u),c=a(6420),_=a.n(c),p=a(47670),m=a.n(p),f=a(51348),v=a.n(f);async function h(e,s){if("POST"!==e.method)return s.json({msg:"Failed!"});let a=await _()(e,s,!0);if(!a)return s.json({success:!1,msg:"Unauthorized"});let t=e.body,r=t.paradigm;if(r?.match(/database/)){let e=await m()({dbFullName:"datasquirel",tableName:"user_users",data:(()=>{let e=Object.keys(t),s={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(s[e]=t[e])}),s.user_id=a.id,s.password=o()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:t.password}),s.user_type="database",s.email=t.email_address,s.image="/images/user-preset.png",s.image_thumbnail="/images/user-preset-thumbnail.png",delete s.email_address,s})()});s.json({success:!!e?.insertId,msg:"New User User Added",newUserId:e.insertId})}else{if(a?.email===t.email_address)return s.json({success:!1,msg:"Can't Invite yourself"});let e=await v()("SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?",[t.email_address,a.id]);if(e&&e[0])return s.json({success:!1,msg:"User Already Invited"});await m()({dbFullName:"datasquirel",tableName:"invitations",data:{inviting_user_id:a.id,invited_user_email:t.email_address,database_access:t.database_access,priviledge:t.priviledge,db_tables_data:t.db_tables}});let r=await d()({to:t.email_address,subject:`${a.first_name} ${a.last_name} Invited you`,text:`${a.first_name} ${a.last_name} has invited you to manage a datasquirel account`,html:`
${a.first_name} ${a.last_name} has invited you to manage a datasquirel account.
Accept Invitation
`});s.json({success:!!r?.accepted,msg:"This is an invitation request"})}}let S=(0,n.M)(t,"default"),g=(0,n.M)(t,"config"),b=new r.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:t})},79531:(e,s,a)=>{let t=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:s,text:a,html:i,alias:n}){let l;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let d=(n?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!t.existsSync("./email/index.html"))return;let u=t.readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,i||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let t={};t.from=`"Datasquirel" <${d}>`,t.sender=d,n&&(t["replyTo "]=d),t.to=e,t.subject=s,t.text=a,t.html=u,l=await r.sendMail(t)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},6420:(e,s,a)=>{a(81630);let t=a(51348),r=a(72907),i=a(29021);async function n(e,s,a,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let l=r(e.cookies.datasquirelAuthKey);if(!l)return null;let d=JSON.parse(l);if(!d.csrf_k||a&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(a&&!i.existsSync(`${u}/${d.csrf_k}`))return null;if(0==d.verification_status&&!a){let e=await t(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&s.setHeader("Set-Cookie",["user_refresh=1"])}return d?.date&&Date.now()-d.date>6048e5?null:d}e.exports=n},72907:(e,s,a)=>{let{scryptSync:t,createDecipheriv:r}=a(55511),{Buffer:i}=a(79428);e.exports=e=>{let s=r("aes-192-cbc",t(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),i.alloc(16,0));try{let a=s.update(e,"hex","utf8");return a+=s.final("utf8")}catch(e){return null}}}};var s=require("../../webpack-api-runtime.js");s.C(e);var a=e=>s(s.s=e),t=s.X(0,[4050],()=>a(21110));module.exports=t})();