dsql-admin/dsql-app/.local_dist/server/pages/api/acceptUserInvitation.js
Benjamin Toby bc037e839f Updates
2024-12-15 12:27:16 +01:00

16 lines
5.6 KiB
JavaScript

"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,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>v,routeModule:()=>N});var s={};t.r(s),t.d(s,{default:()=>g});var i=t(89947),a=t(2706),n=t(96762),l=t(6420),o=t.n(l),u=t(48225),d=t.n(u),_=t(27825),c=t.n(_),p=t(51348),m=t.n(p),E=t(47670),f=t.n(E);async function g(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await o()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=c().cloneDeep(e.body),i=s.inviting_user_id,a=s.invited_user_email,n=s.database_access,l=s.priviledge;try{let e=await m()("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[i,t.id,t.email]);if(e&&e[0])return r.json({success:!1});let s=await f()({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:i,invited_user_id:t.id,database_access:n,user_priviledge:l,user_type:"admin",first_name:t.first_name,last_name:t.last_name,email:t.email,username:t.first_name,image:t.image,image_thumbnail:t.image_thumbnail}});await m()("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[i,a]);let o=await m()("SELECT db_tables_data FROM invitations WHERE inviting_user_id=?",[i]);if(await m()(`DELETE FROM delegated_user_tables WHERE root_user_id='${i}' AND delegated_user_id='${t.id}'`),o&&o[0]){let e=o[0].db_tables_data.split("|");for(let r=0;r<e.length;r++){let[s,a]=e[r].split("-");await f()({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:t.id,root_user_id:i,database:s,table:a,priviledge:l}})}}r.json({success:!!s?.insertId})}catch(s){d()({component:"/api/acceptUserInvitation/catch-error",message:s.message,user:t,req:e}),r.json({success:!1})}}t(29021);let v=(0,n.M)(s,"default"),S=(0,n.M)(s,"config"),N=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/acceptUserInvitation",pathname:"/api/acceptUserInvitation",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),i=t(72835),a=t(29021),n=t(31341);async function l(e,r,t,l){let{keyCookieName:o,csrfCookieName:u}=n();if(!e.cookies?.[o]?.match(/./))return null;let d=i({encryptedString:e.cookies[o]});if(!d)return null;let _=JSON.parse(d);if(!_.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${c}/${_.csrf_k}`))return null;if(0==_.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return _?.date&&Date.now()-_.date>6048e5?null:_}e.exports=l},31341:e=>{e.exports=function(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),n=r;e?.userId&&(n+=`user_${e.userId}_`),a&&(n+=`${a}_`),n+=t;let l=r;e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),l+=s;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),{keyCookieName:n,csrfCookieName:l,oneTimeCodeName:o+=i}}},48225:(e,r,t)=>{let s=t(29021),{IncomingMessage:i}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:i,req:a}){let n=new Date,l=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||s||r||a.socket.remoteAddress;if(!i)return null;return String(i)}catch(e){return null}})();try{let i=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(i+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),a?.url&&(i+=`
URL: ${a.url}`),a?.body&&(i+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),l&&(i+=`
IP: ${l}`),i+=`
Date: ${n.toDateString()}
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",i),s.appendFileSync("./.tmp/error.log",`
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:s,createDecipheriv:i}=t(55511),{Buffer:a}=t(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,o=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=i("aes-192-cbc",s(n,l,o),a.alloc(16,0));try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4050],()=>t(27118));module.exports=s})();