"use strict";(()=>{var e={};e.id=8935,e.ids=[8935],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},27118:(e,t,r)=>{r.r(t),r.d(t,{config:()=>S,default:()=>v,routeModule:()=>h});var i={};r.r(i),r.d(i,{default:()=>E});var a=r(89947),s=r(2706),n=r(96762),l=r(6420),u=r.n(l),o=r(77538),d=r.n(o),c=r(27825),_=r.n(c),m=r(51348),p=r.n(m),f=r(47670),g=r.n(f);async function E(e,t){if("POST"!==e.method)return t.json({user:null,msg:"Registration Failed!"});let r=await u()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let i=_().cloneDeep(e.body),a=i.inviting_user_id,s=i.invited_user_email,n=i.database_access,l=i.priviledge;try{let e=await p()("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[a,r.id,r.email]);if(e&&e[0])return t.json({success:!1});let i=await g()({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:a,invited_user_id:r.id,database_access:n,user_priviledge:l,user_type:"admin",first_name:r.first_name,last_name:r.last_name,email:r.email,username:r.first_name,image:r.image,image_thumbnail:r.image_thumbnail}});await p()("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[a,s]);let u=await p()("SELECT db_tables_data FROM invitations WHERE inviting_user_id=?",[a]);if(await p()(`DELETE FROM delegated_user_tables WHERE root_user_id='${a}' AND delegated_user_id='${r.id}'`),u&&u[0]){let e=u[0].db_tables_data.split("|");for(let t=0;t{let i=r(29021),{IncomingMessage:a}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:a,req:s}){let n=new Date,l=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],t=s.headers["x-real-ip"],r=s.headers["cf-connecting-ip"],i=Array.isArray(e)?e[0]:e?.split(",")[0],a=r||i||t||s.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR =========================== Error Message: ${t} Component: ${r}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=` User Id: ${e?.id} User Name: ${e?.first_name} ${e?.last_name} User Email: ${e?.email}`),s?.url&&(a+=` URL: ${s.url}`),s?.body&&(a+=` Request Body: ${JSON.stringify(s.body,null,4)}`),l&&(a+=` IP: ${l}`),a+=` Date: ${n.toDateString()} ========================================`,i.existsSync("./.tmp/error.log")||i.writeFileSync("./.tmp/error.log","","utf-8");let u=i.readFileSync("./.tmp/error.log","utf-8");i.writeFileSync("./.tmp/error.log",a),i.appendFileSync("./.tmp/error.log",` ${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,t,r)=>{r(81630);let i=r(51348),a=r(72907),s=r(29021);async function n(e,t,r,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let l=a(e.cookies.datasquirelAuthKey);if(!l)return null;let u=JSON.parse(l);if(!u.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${u.csrf_k}`)))return null;let o=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!o)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!s.existsSync(`${o}/${u.csrf_k}`))return null;if(0==u.verification_status&&!r){let e=await i(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}e.exports=n},72907:(e,t,r)=>{let{scryptSync:i,createDecipheriv:a}=r(55511),{Buffer:s}=r(79428);e.exports=e=>{let t=a("aes-192-cbc",i(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),s.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=e=>t(t.s=e),i=t.X(0,[4050],()=>r(27118));module.exports=i})();