dsql-admin/dsql-app/.local_dist/server/pages/api/updateDbUser.js

1 line
8.5 KiB
JavaScript
Raw Normal View History

2024-12-09 12:27:08 +00:00
"use strict";(()=>{var e={};e.id=3683,e.ids=[3683],e.modules={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")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},96016:(e,r,t)=>{t.r(r),t.d(r,{config:()=>d,default:()=>_,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>p});var n=t(89947),o=t(2706),a=t(96762),c=t(33364),i=t.n(c),l=t(6420),u=t.n(l);async function p(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});if(!await u()(e,r,!0))return r.json({success:!1,msg:"Unauthorized"});let{dbFullName:t,payload:s}=e.body,n=(()=>{let e=Object.keys(s),r={};return e.forEach(e=>{!e?.match(/user_type|priviledge|database_access|databases?|confirm/)&&(e?.match(/databases|confirm/)||(r[e]=s[e]))}),r})(),o=await i()({dbFullName:t,tableName:"users",identifierColumnName:"id",identifierValue:s.id,data:{...n},dbContext:"Dsql User",paradigm:"Full Access"});r.json({success:!!o?.affectedRows,msg:o?.affectedRows?"User Updated":o})}let _=(0,a.M)(s,"default"),d=(0,a.M)(s,"config"),S=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/updateDbUser",pathname:"/api/updateDbUser",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),n=t(72835),o=t(29021),a=t(31341);async function c(e,r,t,c){let{keyCookieName:i,csrfCookieName:l}=a();if(!e.cookies?.[i]?.match(/./))return null;let u=n({encryptedString:e.cookies[i]});if(!u)return null;let p=JSON.parse(u);if(!p.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${p.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&&!o.existsSync(`${_}/${p.csrf_k}`))return null;if(0==p.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${p.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return p?.date&&Date.now()-p.date>6048e5?null:p}e.exports=c},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",n=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),o+=t;let a=r;return e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),{keyCookieName:o,csrfCookieName:a+=s}}},33364:(e,r,t)=>{let s=t(72583),n=t(16570),o=t(51348),a=t(21339),c=t(20503),i=t(44900);async function l({dbContext:e,paradigm:r,dbFullName:t,tableName:l,data:u,tableSchema:p,identifierColumnName:_,identifierValue:d,encryptionKey:S,encryptionSalt:f,useLocal:D}){if(!u||!Object.keys(u).length)return null;let E=!!D||!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),g=D?i:E?o:a,h=Object.keys(u),m=[],v=[];for(let e=0;e<h.length;e++)try{let r=h[e],t=u[r],o=p?p?.fields?.filter(e=>e.fieldName===r):null,a=o&&o[0]?o[0]:null;if(null==t||void 0==t)continue;a?.richText&&(t=s(t,n)),a?.encrypted&&(t=c({data:t,encryptionKey:S,encryptionSalt:f})),"object"==typeof t&&(t=JSON.stringify(t)),a?.pattern&&!new RegExp(a.pattern,a.patternFlags||"").test(t)&&(console.log("DSQL: Pattern not matched =>",t),t=""),"string"==typeof t&&t.match(/^null$/i)&&(t={toSqlString:function(){return"NULL"}}),"string"!=typeof t||t.match(/./i)||(t={toSqlString:function(){return"NULL"}}),m.push(`\`${r}\`=?`),"number"==typeof t?v.push(String(t)):v.push(t)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}m.push(`date_updated='${Date()}'`),m.push(`date_updated_code='${Date.now()}'`);let L=`UPDATE ${l} SET ${m.join(",")} WHERE \`