"use strict";(()=>{var e={};e.id=3953,e.ids=[3953],e.modules={47795:e=>{e.exports=require("generate-password")},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")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},68140:(e,i,r)=>{r.r(i),r.d(i,{config:()=>h,default:()=>E,routeModule:()=>I});var s={};r.r(s),r.d(s,{default:()=>b});var t=r(89947),a=r(2706),n=r(96762),l=r(29021),d=r.n(l),u=r(68829),o=r(96052),m=r(67619),c=r(33873),p=r.n(c),g=r(79646),_=r(67580),v=r(48786),f=r(98e3),A=r(30802),S=r(83919);async function b(e,i){if("POST"!==e.method)return i.json({user:null,msg:"Registration Failed!"});let r=e.body,{inviteObject:s}=r,t=r.first_name,a=r.last_name,n=r.email,l=r.password,c=r.username;if(!n.match(/.*@.*\..*/))return i.json({user:null,msg:"Invalid Email"});if(!t.match(/^[a-zA-Z]+$/)||!a.match(/^[a-zA-Z]+$/))return i.json({user:null,msg:"Invalid Name"});if(l?.match(/ /))return i.json({user:null,msg:"Invalid Password"});if(c?.match(/ /))return i.json({user:null,msg:"Invalid Username"});try{let e=(0,S.A)({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:l}),r=await (0,v.A)(`SELECT * FROM users WHERE email='${n}'`);if(r&&r[0])return i.json({user:null,msg:"User Already Exists"});let m=await (0,f.A)({dbFullName:"datasquirel",tableName:"users",data:{first_name:t,last_name:a,email:n,password:e,username:c}});if(!m?.insertId)return i.json({user:null,msg:"Adding User to Database failed"});await (0,_.A)({userId:m.insertId});let b=(0,u.A)({data:JSON.stringify({id:m.insertId,email:n,dateCode:Date.now()})});(0,o.A)({to:n,subject:"Verify Email Address",text:"Please click the link to verify your email address",html:d().readFileSync("./email/send-email-verification-link.html","utf8").replace(/{{host}}/,process.env.DSQL_HOST||"").replace(/{{token}}/,b||"")}).then(e=>{}),"production".match(/production/),m.insertId,m.insertId;let E=process.env.DSQL_STATIC_SERVER_DIR;if(!E)throw console.log("Static File ENV not Found!"),Error("No Static Path");let h=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${m.insertId}`,I=p().join(E,`images/user-images/user-${m.insertId}`);d().mkdirSync(h,{recursive:!0}),d().mkdirSync(I,{recursive:!0}),d().writeFileSync(`${h}/main.json`,JSON.stringify([]),"utf8");let y=p().join(E,`images/user-images/user-${m.insertId}/user-${m.insertId}-profile.jpg`),w=p().join(E,`images/user-images/user-${m.insertId}/user-${m.insertId}-profile-thumbnail.jpg`),N=y.replace(E,process.env.DSQL_STATIC_HOST||""),j=w.replace(E,process.env.DSQL_STATIC_HOST||"");if(d().copyFileSync("./public/images/user-preset.png",y),d().copyFileSync("./public/images/user-preset-thumbnail.png",w),(0,g.execSync)(`chmod 644 ${y} ${w}`),await (0,A.A)({dbFullName:"datasquirel",tableName:"users",identifierColumnName:"id",identifierValue:m.insertId,data:{image:N,image_thumbnail:j}}),s){let e=await (0,f.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:s.invite,invited_user_id:m.insertId,database_access:s.database_access,user_priviledge:s.priviledge,user_type:"admin",first_name:t,last_name:a,email:n,username:c,image:N,image_thumbnail:j}});await (0,v.A)("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[s.invite,n]);let i=await (0,v.A)("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[s.invite,n]);if(await (0,v.A)("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[s.invite,e.insertId]),i&&i[0]){let r=i[0].db_tables_data.split("|");for(let i=0;i<r.length;i++){let[t,a]=r[i].split("-");await (0,f.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:e.insertId,root_user_id:s.invite,database:t,table:a,priviledge:s.priviledge}})}}}i.json(m)}catch(e){console.log(`Error in creating user => ${e.message}`),(0,m.A)({component:"/api/registerUser/main-catch-error",message:e.message,user:{first_name:t,last_name:a,email:n}}),i.json({user:null})}}let E=(0,n.M)(s,"default"),h=(0,n.M)(s,"config"),I=new t.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/registerUser",pathname:"/api/registerUser",bundlePath:"",filename:""},userland:s})},83919:(e,i,r)=>{r.d(i,{A:()=>a});var s=r(55511),t=r(31542);function a({password:e,encryptionKey:i}){let{key:r}=(0,t.A)({encryptionKey:i});if(!r?.match(/.{8,}/))throw Error("Encryption key is invalid");let a=(0,s.createHmac)("sha512",r);return a.update(e),a.digest("base64")}}};var i=require("../../webpack-api-runtime.js");i.C(e);var r=e=>i(i.s=e),s=i.X(0,[2319],()=>r(68140));module.exports=s})();