2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 5402 ;
exports . ids = [ 5402 ] ;
exports . modules = {
/***/ 2029 :
/***/ ( ( module ) => {
module . exports = require ( "datasquirel/functions/hashPassword" ) ;
/***/ } ) ,
/***/ 6517 :
/***/ ( ( module ) => {
module . exports = require ( "lodash" ) ;
/***/ } ) ,
/***/ 5184 :
/***/ ( ( module ) => {
module . exports = require ( "nodemailer" ) ;
/***/ } ) ,
/***/ 6109 :
/***/ ( ( module ) => {
module . exports = require ( "sanitize-html" ) ;
/***/ } ) ,
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 4300 :
/***/ ( ( module ) => {
module . exports = require ( "buffer" ) ;
/***/ } ) ,
/***/ 6113 :
/***/ ( ( module ) => {
module . exports = require ( "crypto" ) ;
/***/ } ) ,
/***/ 7147 :
/***/ ( ( module ) => {
module . exports = require ( "fs" ) ;
/***/ } ) ,
/***/ 3685 :
/***/ ( ( module ) => {
module . exports = require ( "http" ) ;
/***/ } ) ,
/***/ 1017 :
/***/ ( ( module ) => {
module . exports = require ( "path" ) ;
/***/ } ) ,
/***/ 9210 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "default" : ( ) => ( /* binding */ handler )
/* harmony export */ } ) ;
/* harmony import */ var _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 6926 ) ;
/* harmony import */ var _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _0 _ _ ) ;
/* harmony import */ var datasquirel _functions _hashPassword _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 2029 ) ;
/* harmony import */ var datasquirel _functions _hashPassword _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( datasquirel _functions _hashPassword _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 5338 ) ;
/* harmony import */ var _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _3 _ _ ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 2224 ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ ) ;
// @ts-check
/ * *
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* Imports
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* /
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* API handler
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* @ type { import ( "next" ) . NextApiHandler }
* / a s y n c f u n c t i o n h a n d l e r ( r e q , r e s ) {
/ * *
* Check method
*
* @ description Check request method and return if invalid
* / i f ( r e q . m e t h o d ! = = " P O S T " ) r e t u r n r e s . j s o n ( {
msg : "Failed!"
} ) ;
/ * *
* User auth
*
* @ description Authenticate user
* / c o n s t u s e r = a w a i t _ f u n c t i o n s _ b a c k e n d _ u s e r A u t h _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 2 _ _ _ d e f a u l t ( ) ( r e q , r e s , t r u e ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
/ * *
* User auth
*
* @ description Authenticate user
* / / / const sanitizedReqBody = sanitizeSql ( req . body ) ;
const sanitizedReqBody = req . body ;
const paradigm = sanitizedReqBody . paradigm ;
/ * *
* Input Validation
*
* @ description Input Validation
* / i f ( p a r a d i g m ? . m a t c h ( / d a t a b a s e / ) ) {
const newUser = await _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "user_users" ,
data : ( ( ) => {
const reqBodyKeys = Object . keys ( sanitizedReqBody ) ;
/** @type {any} */ const finalData = { } ;
reqBodyKeys . forEach ( ( key ) => {
if ( key ? . match ( /paradigm|priviledge|database_access|databases|confirm/ ) ) return ;
finalData [ key ] = sanitizedReqBody [ key ] ;
} ) ;
finalData [ "user_id" ] = user . id ;
finalData [ "password" ] = datasquirel _functions _hashPassword _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
encryptionKey : process . env . DSQL _ENCRYPTION _PASSWORD || "" ,
password : sanitizedReqBody . password
} ) ;
finalData [ "user_type" ] = "database" ;
finalData [ "email" ] = sanitizedReqBody . email _address ;
finalData [ "image" ] = "/images/user_images/user-preset.png" ;
finalData [ "image_thumbnail" ] = "/images/user_images/user-preset-thumbnail.png" ;
delete finalData [ "email_address" ] ;
return finalData ;
} ) ( )
} ) ;
res . json ( {
success : newUser ? . insertId ? true : false ,
msg : "New User User Added" ,
newUserId : newUser . insertId
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} else {
if ( user ? . email === sanitizedReqBody . email _address ) {
return res . json ( {
success : false ,
msg : "Can't Invite yourself"
} ) ;
}
const existingInvitation = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default ( ) ( ` SELECT * FROM invitations WHERE invited_user_email=? AND inviting_user_id=? ` , [
sanitizedReqBody . email _address ,
user . id
] ) ;
if ( existingInvitation && existingInvitation [ 0 ] ) {
return res . json ( {
success : false ,
msg : "User Already Invited"
} ) ;
}
const newInvitation = await _package _shared _functions _backend _db _addDbEntry _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "invitations" ,
data : {
inviting _user _id : user . id ,
invited _user _email : sanitizedReqBody . email _address ,
database _access : sanitizedReqBody . database _access ,
priviledge : sanitizedReqBody . priviledge ,
db _tables _data : sanitizedReqBody . db _tables
}
} ) ;
const sendInvitationMail = await _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ( {
to : sanitizedReqBody . email _address ,
subject : ` ${ user . first _name } ${ user . last _name } Invited you ` ,
text : ` ${ user . first _name } ${ user . last _name } has invited you to manage a datasquirel account ` ,
html : `
< h2 > $ { user . first _name } $ { user . last _name } has invited you to manage a datasquirel account . < / h 2 >
< a href = "${process.env.DSQL_HOST}/create-account?invite=${user.id}&database_access=${sanitizedReqBody.database_access}&priviledge=${sanitizedReqBody.priviledge}&email=${sanitizedReqBody.email_address}" > Accept Invitation < / a >
`
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
res . json ( {
success : sendInvitationMail ? . accepted ? true : false ,
msg : "This is an invitation request"
} ) ;
}
}
/***/ } )
} ;
;
// load runtime
var _ _webpack _require _ _ = require ( "../../webpack-api-runtime.js" ) ;
_ _webpack _require _ _ . C ( exports ) ;
var _ _webpack _exec _ _ = ( moduleId ) => ( _ _webpack _require _ _ ( _ _webpack _require _ _ . s = moduleId ) )
2024-11-05 14:18:40 +00:00
var _ _webpack _exports _ _ = _ _webpack _require _ _ . X ( 0 , [ 2224 , 6825 , 3017 , 3403 , 7547 , 5886 , 5338 , 6926 ] , ( ) => ( _ _webpack _exec _ _ ( 9210 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;