"use strict";(()=>{var e={};e.id=2350,e.ids=[2350],e.modules={76102:e=>{e.exports=require("@moduletrace/datasquirel/dist/client")},39383:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/actions/users/user-auth")},65967:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson")},93726:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy")},30889:e=>{e.exports=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify")},60818:e=>{e.exports=require("dotenv")},47795:e=>{e.exports=require("generate-password")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},33873:e=>{e.exports=require("path")},49844:(e,r,s)=>{s.r(r),s.d(r,{config:()=>g,default:()=>m,routeModule:()=>q});var a={};s.r(a),s.d(a,{default:()=>c});var t=s(89947),i=s(2706),d=s(96762),u=s(69842),o=s(67619),n=s(48786),l=s(68829),p=s(5437);async function c(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let{user:s,appData:a}=await (0,u.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{data:t,edit:i,prev:d,grants:c}=e.body;try{if(!d?.id)throw Error("Invalid existing DB entry");let e=await (0,n.A)("SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",[d.id,s.id]),a=s?.id==Number(process.env.DSQL_SU_USER_ID),i=e?.[0];if(!i?.id)throw Error("Active User couldn't be verified");let{host:u,password:o,username:m}=t,g=a&&m||`dsql_user_${s.id}`;if(!u)throw Error("No host provided");let q=String(u).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,"");if(i.host!=t.host||i.username!=g){let e=await (0,n.A)("SELECT * FROM mariadb_users WHERE user_id=? AND username=? AND host=?",[s.id,g,q]);e?.[0]?.id||await (0,n.A)(`RENAME USER '${d.username}'@'${i.host}' TO '${g}'@'${q}'`)}let A=(0,l.A)({data:o}),E=A==i.password?i.password:A;await (0,n.A)("UPDATE mariadb_users SET username=?, host=?, password=?, grants=? WHERE id=?",[g,q,E,JSON.stringify(c),i.id]),await (0,n.A)(`SET PASSWORD FOR '${g}'@'${q}' = PASSWORD('${o}');`),await (0,p.A)({userId:s.id,mariadbUsername:g,mariadbUserHost:q,sqlUserID:i.id}),r.json({success:!0})}catch(e){(0,o.A)({component:"/api/acceptUserInvitation/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Error in adding SQL user =>"+e.message,err:e.message})}}let m=(0,d.M)(a,"default"),g=(0,d.M)(a,"config"),q=new t.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/sql-users/update",pathname:"/api/sql-users/update",bundlePath:"",filename:""},userland:a})}};var r=require("../../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),a=r.X(0,[6133],()=>s(49844));module.exports=a})();