4 lines
5.5 KiB
JavaScript
4 lines
5.5 KiB
JavaScript
"use strict";(()=>{var e={};e.id=3812,e.ids=[3812],e.modules={43499:e=>{e.exports=require("@moduletrace/datasquirel/functions/hashPassword")},27825:e=>{e.exports=require("lodash")},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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},21110:(e,s,a)=>{a.r(s),a.d(s,{config:()=>h,default:()=>g,routeModule:()=>E});var t={};a.r(t),a.d(t,{default:()=>S});var r=a(89947),i=a(2706),n=a(96762),l=a(59474),o=a.n(l),d=a(43499),u=a.n(d),c=a(6420),_=a.n(c),p=a(47670),m=a.n(p),f=a(51348),v=a.n(f);async function S(e,s){if("POST"!==e.method)return s.json({msg:"Failed!"});let a=await _()(e,s,!0);if(!a)return s.json({success:!1,msg:"Unauthorized"});let t=e.body,r=t.paradigm;if(r?.match(/database/)){let e=await m()({dbFullName:"datasquirel",tableName:"user_users",data:(()=>{let e=Object.keys(t),s={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(s[e]=t[e])}),s.user_id=a.id,s.password=u()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:t.password}),s.user_type="database",s.email=t.email_address,s.image="/images/user-preset.png",s.image_thumbnail="/images/user-preset-thumbnail.png",delete s.email_address,s})()});s.json({success:!!e?.insertId,msg:"New User User Added",newUserId:e.insertId})}else{if(a?.email===t.email_address)return s.json({success:!1,msg:"Can't Invite yourself"});let e=await v()("SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?",[t.email_address,a.id]);if(e&&e[0])return s.json({success:!1,msg:"User Already Invited"});await m()({dbFullName:"datasquirel",tableName:"invitations",data:{inviting_user_id:a.id,invited_user_email:t.email_address,database_access:t.database_access,priviledge:t.priviledge,db_tables_data:t.db_tables}});let r=await o()({to:t.email_address,subject:`${a.first_name} ${a.last_name} Invited you`,text:`${a.first_name} ${a.last_name} has invited you to manage a datasquirel account`,html:`
|
|
<h2>${a.first_name} ${a.last_name} has invited you to manage a datasquirel account.</h2>
|
|
<a href="${process.env.DSQL_HOST}/create-account?invite=${a.id}&database_access=${t.database_access}&priviledge=${t.priviledge}&email=${t.email_address}">Accept Invitation</a>
|
|
`});s.json({success:!!r?.accepted,msg:"This is an invitation request"})}}let g=(0,n.M)(t,"default"),h=(0,n.M)(t,"config"),E=new r.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:t})},6420:(e,s,a)=>{a(81630);let t=a(51348),r=a(72835),i=a(29021),n=a(31341);async function l(e,s,a,l){let{keyCookieName:o,csrfCookieName:d}=n();if(!e.cookies?.[o]?.match(/./))return null;let u=r({encryptedString:e.cookies[o]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||a&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.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(a&&!i.existsSync(`${_}/${c.csrf_k}`))return null;if(0==c.verification_status&&!a){let e=await t(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&s.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=l},31341:e=>{e.exports=function(e){let s=process.env.DSQL_COOKIES_PREFIX||"dsql_",a=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",r=s;e?.userId&&(r+=`user_${e.userId}_`),e?.database&&(r+=`${e.database}_`),r+=a;let i=s;return e?.userId&&(i+=`user_${e.userId}_`),e?.database&&(i+=`${e.database}_`),{keyCookieName:r,csrfCookieName:i+=t}}},59474:(e,s,a)=>{let t=a(29021),r=a(21572).createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});e.exports=async function({to:e,subject:s,text:a,html:i,alias:n}){let l;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let o=(n?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!t.existsSync("./email/index.html"))return;let d=t.readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,i||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let t={};t.from=`"Datasquirel" <${o}>`,t.sender=o,n&&(t["replyTo "]=o),t.to=e,t.subject=s,t.text=a,t.html=d,l=await r.sendMail(t)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},72835:(e,s,a)=>{let{scryptSync:t,createDecipheriv:r}=a(55511),{Buffer:i}=a(79428);e.exports=({encryptedString:e,encryptionKey:s,encryptionSalt:a})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=s||process.env.DSQL_ENCRYPTION_PASSWORD,l=a||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 d=r("aes-192-cbc",t(n,l,o),i.alloc(16,0));try{let s=d.update(e,"hex","utf8");return s+=d.final("utf8")}catch(s){return console.log("Error in decrypting =>",s.message),e}}}};var s=require("../../webpack-api-runtime.js");s.C(e);var a=e=>s(s.s=e),t=s.X(0,[4050],()=>a(21110));module.exports=t})(); |