16 lines
5.6 KiB
JavaScript
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")},34042:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>m,routeModule:()=>E});var s={};t.r(s),t.d(s,{default:()=>p});var i=t(89947),a=t(2706),n=t(96762),l=t(69842),u=t(67619),o=t(27825),d=t.n(o),_=t(48786),c=t(98e3);async function p(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,l.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=d().cloneDeep(e.body),i=s.inviting_user_id,a=s.invited_user_email,n=s.database_access,o=s.priviledge;try{let e=await (0,_.A)("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 (0,c.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:i,invited_user_id:t.id,database_access:n,user_priviledge:o,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 (0,_.A)("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[i,a]);let l=await (0,_.A)("SELECT db_tables_data FROM invitations WHERE inviting_user_id=?",[i]);if(await (0,_.A)(`DELETE FROM delegated_user_tables WHERE root_user_id='${i}' AND delegated_user_id='${t.id}'`),l&&l[0]){let e=l[0].db_tables_data.split("|");for(let r=0;r<e.length;r++){let[s,a]=e[r].split("-");await (0,c.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:t.id,root_user_id:i,database:s,table:a,priviledge:o}})}}r.json({success:!!s?.insertId})}catch(s){(0,u.default)({component:"/api/acceptUserInvitation/catch-error",message:s.message,user:t,req:e}),r.json({success:!1})}}let m=(0,n.M)(s,"default"),f=(0,n.M)(s,"config"),E=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/acceptUserInvitation",pathname:"/api/acceptUserInvitation",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>u});var s=t(48786),i=t(95969),a=t(29021),n=t.n(a),l=t(89159);async function u(e,r,t){let{keyCookieName:a,csrfCookieName:u}=(0,l.A)();if(!e.cookies?.[a]?.match(/./))return null;let o=(0,i.A)({encryptedString:e.cookies[a]});if(!o)return null;let d=JSON.parse(o);if(!d.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(d.csrf_k)))return null;let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!n().existsSync(`${_}/${d.csrf_k}`))return null;if(0==d.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return d?.date&&Date.now()-d.date>6048e5?null:d}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(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 u=r;return e?.userId&&(u+=`user_${e.userId}_`),a&&(u+=`${a}_`),{keyCookieName:n,csrfCookieName:l,oneTimeCodeName:u+=i}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>a});var s=t(29021),i=t.n(s);async function a({user:e,message:r,component:t,noMail:s,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 s=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),a?.url&&(s+=`
|
|
URL: ${a.url}`),a?.body&&(s+=`
|
|
Request Body: ${JSON.stringify(a.body,null,4)}`),l&&(s+=`
|
|
IP: ${l}`),s+=`
|
|
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",s),i().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(55511),i=t(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,n=t||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!n?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=(0,s.scryptSync)(a,n,l),o=i.Buffer.alloc(16,0),d=(0,s.createDecipheriv)("aes-192-cbc",u,o);try{let r=d.update(e,"hex","utf8");return r+=d.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,[1251],()=>t(34042));module.exports=s})(); |