dsql-admin/dsql-app/.local_dist/server/pages/api/sendEmailVerificationLink.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

13 lines
5.3 KiB
JavaScript

"use strict";(()=>{var e={};e.id=7714,e.ids=[7714],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},21572:e=>{e.exports=require("nodemailer")},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")},96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},11074:(e,t,r)=>{r.r(t),r.d(t,{config:()=>S,default:()=>d,routeModule:()=>_});var s={};r.r(s),r.d(s,{default:()=>f});var n=r(89947),i=r(2706),a=r(96762),o=r(6420),l=r.n(o);let c=r(29021),u=r(79531),p=r(82703);async function f(e,t){if("GET"===e.method){let r=await l()(e,t);if(!r)return t.redirect(307,"/logout");let s=p(JSON.stringify({id:r.id,email:r.email,dateCode:Date.now()})),n=process.env.DSQL_HOST;if(!await u({to:r.email,subject:"Verify Email Address",text:"Please click the link to verify your email address",html:c.readFileSync("./email/send-email-verification-link.html","utf8").replace(/{{host}}/,n||"").replace(/{{token}}/,s||"")}))return t.json({success:!1});t.json({success:!0})}}let d=(0,a.M)(s,"default"),S=(0,a.M)(s,"config"),_=new n.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/sendEmailVerificationLink",pathname:"/api/sendEmailVerificationLink",bundlePath:"",filename:""},userland:s})},79531:(e,t,r)=>{let s=r(29021),n=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:t,text:r,html:i,alias:a}){let o;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let l=(a?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!s.existsSync("./email/index.html"))return;let c=s.readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,i||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let s={};s.from=`"Datasquirel" <${l}>`,s.sender=l,a&&(s["replyTo "]=l),s.to=e,s.subject=t,s.text=r,s.html=c,o=await n.sendMail(s)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return o}},6420:(e,t,r)=>{r(81630);let s=r(51348),n=r(72907),i=r(29021);async function a(e,t,r,a){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=n(e.cookies.datasquirelAuthKey);if(!o)return null;let l=JSON.parse(o);if(!l.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!i.existsSync(`${c}/${l.csrf_k}`))return null;if(0==l.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=a},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:n}=r(55511),{Buffer:i}=r(79428);e.exports=e=>{let t=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),i.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},82703:(e,t,r)=>{let{scryptSync:s,createCipheriv:n}=r(55511),{Buffer:i}=r(79428),a=r(48225);e.exports=(e,t,r)=>{let o=n("aes-192-cbc",s(t||process.env.DSQL_ENCRYPTION_PASSWORD||"",r||process.env.DSQL_ENCRYPTION_SALT||"",24),i.alloc(16,0));try{let t=o.update(e,"utf8","hex");return t+=o.final("hex")}catch(e){return a({component:"encrypt",message:e.message}),null}}},48225:(e,t,r)=>{let s=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:n}){let i=`🚀 SERVER ERROR ===========================
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}
Error Message: ${t}
Component: ${r}
Date: ${Date()}
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let a=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",i),s.appendFileSync("./.tmp/error.log",`
${a}`)}},51348:(e,t,r)=>{let s=r(9973),n=r(21580),i=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:n()}});async function a(...e){try{let t=await i.query(...e);return await i.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=a},21580:(e,t,r)=>{let s=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!s.existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,t)=>{var r;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(r||(r={}))},89947:(e,t,r)=>{e.exports=r(75600)}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=t(t.s=11074);module.exports=r})();