4 lines
5.8 KiB
JavaScript
4 lines
5.8 KiB
JavaScript
"use strict";(()=>{var e={};e.id=3812,e.ids=[3812],e.modules={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,t)=>{t.r(s),t.d(s,{config:()=>h,default:()=>g,routeModule:()=>E});var r={};t.r(r),t.d(r,{default:()=>S});var a=t(89947),i=t(2706),n=t(96762),l=t(59474),o=t.n(l),d=t(6420),u=t.n(d),c=t(47670),_=t.n(c),p=t(51348),m=t.n(p),f=t(14533),v=t.n(f);async function S(e,s){if("POST"!==e.method)return s.json({msg:"Failed!"});let t=await u()(e,s,!0);if(!t)return s.json({success:!1,msg:"Unauthorized"});let r=e.body,a=r.paradigm;if(a?.match(/database/)){let e=await _()({dbFullName:"datasquirel",tableName:"user_users",data:(()=>{let e=Object.keys(r),s={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(s[e]=r[e])}),s.user_id=t.id,s.password=v()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:r.password}),s.user_type="database",s.email=r.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(t?.email===r.email_address)return s.json({success:!1,msg:"Can't Invite yourself"});let e=await m()("SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=?",[r.email_address,t.id]);if(e&&e[0])return s.json({success:!1,msg:"User Already Invited"});await _()({dbFullName:"datasquirel",tableName:"invitations",data:{inviting_user_id:t.id,invited_user_email:r.email_address,database_access:r.database_access,priviledge:r.priviledge,db_tables_data:r.db_tables}});let a=await o()({to:r.email_address,subject:`${t.first_name} ${t.last_name} Invited you`,text:`${t.first_name} ${t.last_name} has invited you to manage a datasquirel account`,html:`
|
|
<h2>${t.first_name} ${t.last_name} has invited you to manage a datasquirel account.</h2>
|
|
<a href="${process.env.DSQL_HOST}/create-account?invite=${t.id}&database_access=${r.database_access}&priviledge=${r.priviledge}&email=${r.email_address}">Accept Invitation</a>
|
|
`});s.json({success:!!a?.accepted,msg:"This is an invitation request"})}}let g=(0,n.M)(r,"default"),h=(0,n.M)(r,"config"),E=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addUserUser",pathname:"/api/addUserUser",bundlePath:"",filename:""},userland:r})},6420:(e,s,t)=>{t(81630);let r=t(51348),a=t(72835),i=t(29021),n=t(31341);async function l(e,s,t,l){let{keyCookieName:o,csrfCookieName:d}=n();if(!e.cookies?.[o]?.match(/./))return null;let u=a({encryptedString:e.cookies[o]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||t&&!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(t&&!i.existsSync(`${_}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await r(`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_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",r=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=s;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=t;let n=s;return e?.userId&&(n+=`user_${e.userId}_`),a&&(n+=`${a}_`),{keyCookieName:i,csrfCookieName:n+=r}}},59474:(e,s,t)=>{let r=t(29021),a=t(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:t,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(!r.existsSync("./email/index.html"))return;let d=r.readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,i||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let r={};r.from=`"Datasquirel" <${o}>`,r.sender=o,n&&(r["replyTo "]=o),r.to=e,r.subject=s,r.text=t,r.html=d,l=await a.sendMail(r)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return l}},72835:(e,s,t)=>{let{scryptSync:r,createDecipheriv:a}=t(55511),{Buffer:i}=t(79428);e.exports=({encryptedString:e,encryptionKey:s,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=s||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 d=a("aes-192-cbc",r(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}}},14533:(e,s,t)=>{let{createHmac:r}=t(55511);e.exports=function({password:e,encryptionKey:s}){let t=s||process.env.DSQL_ENCRYPTION_PASSWORD;if(!t?.match(/.{8,}/))throw Error("Encryption key is invalid");let a=r("sha512",t);return a.update(e),a.digest("base64")}}};var s=require("../../webpack-api-runtime.js");s.C(e);var t=e=>s(s.s=e),r=s.X(0,[4050],()=>t(21110));module.exports=r})(); |