"use strict";(()=>{var e={};e.id=7889,e.ids=[7889],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")},52795:(e,r,s)=>{s.r(r),s.d(r,{config:()=>q,default:()=>h,routeModule:()=>f});var a={};s.r(a),s.d(a,{default:()=>g});var t=s(89947),i=s(2706),u=s(96762),o=s(47795),d=s.n(o),n=s(69842),l=s(67619),c=s(48786),p=s(68829),m=s(5437);async function g(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let{user:s,appData:a}=await (0,n.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{data:t,edit:i,grants:u}=e.body;try{process.env.DSQL_DB_HOST;let e=s?.id==Number(process.env.DSQL_SU_USER_ID),{host:a,password:i,username:o}=t,n=e&&o?.match(/./)?o:`dsql_user_${s.id}`;if(!a.match(/./))throw Error("Invalid host");let l=String(a).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,""),g=i?.match(/./)?i:d().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),h=await (0,c.A)("SELECT * FROM mysql.user WHERE User=? AND Host=?",[n,l]);if(h?.[0]?.User)throw Error("SQL User already exists. Remember if you have the '%' host on your primary user, it catches all other hosts.");let q=await (0,c.A)("SELECT COUNT(*) FROM mariadb_users WHERE user_id = ?",[s.id]);if(q?.[0]?.["COUNT(*)"]>=10)throw Error("User limit reached");let f=(0,p.A)({data:g}),E=await (0,c.A)("INSERT INTO mariadb_users (user_id, username, host, password, grants) VALUES (?, ?, ?, ?, ?)",[s.id,n,l,f,JSON.stringify(u)]);if(!E?.insertId)throw Error("Error in adding SQL user");await (0,m.A)({userId:s.id,mariadbUsername:n,mariadbUserHost:l,sqlUserID:E.insertId}),r.json({success:!0})}catch(e){console.log("Create MariaDB user ERROR:",e.message),(0,l.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 h=(0,u.M)(a,"default"),q=(0,u.M)(a,"config"),f=new t.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/sql-users/create",pathname:"/api/sql-users/create",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(52795));module.exports=a})();