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

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