Skip to content
Snippets Groups Projects
Commit 539dde44 authored by Sebastian's avatar Sebastian
Browse files

fixed signedUrl issues, added email sending func

parent ef532f95
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,8 @@
"aws-sdk": "^2.185.0",
"body-parser": "^1.17.2",
"multer": "^1.3.0",
"multer-s3": "^2.7.0"
"multer-s3": "^2.7.0",
"nodemailer": "^4.4.2"
},
"peerDependencies": {
"@pubsweet/logger": "^0.0.1",
......
......@@ -3,23 +3,26 @@ const AWS = require('aws-sdk')
const multer = require('multer')
const multerS3 = require('multer-s3')
const uuid = require('uuid')
const nodemailer = require('nodemailer')
AWS.config.update({
secretAccessKey: process.env.AWS_SECRET_KEY,
accessKeyId: process.env.AWS_ACCESS_KEY,
region: process.env.AWS_REGION,
})
const AWSBackend = app => {
app.use(bodyParser.json())
const authBearer = app.locals.passport.authenticate('bearer', {
session: false,
})
AWS.config.update({
secretAccessKey: process.env.AWS_SECRET_KEY,
accessKeyId: process.env.AWS_ACCESS_KEY,
region: process.env.AWS_REGION,
})
const s3 = new AWS.S3()
const upload = multer({
storage: multerS3({
s3,
bucket: process.env.AWS_BUCKET,
contentType: multerS3.AUTO_CONTENT_TYPE,
contentType: (req, file, cb) => {
cb(null, file.mimetype)
},
key: (req, file, cb) => {
const fileKey = `${req.body.fragmentId}/${uuid.v4()}`
cb(null, fileKey)
......@@ -49,7 +52,6 @@ const AWSBackend = app => {
if (req.fileValidationError !== undefined) {
return res.status(400).json({ error: req.fileValidationError })
}
res.status(200).json({
id: req.file.key,
name: req.file.originalname,
......@@ -85,6 +87,55 @@ const AWSBackend = app => {
res.status(204).json()
})
})
app.post('/api/aws/email', authBearer, async (req, res) => {
AWS.config.update({
secretAccessKey: process.env.SES_SECRET_KEY,
accessKeyId: process.env.SES_ACCESS_KEY,
region: process.env.AWS_REGION,
})
const reqUser = await app.locals.models.User.find(req.user)
if (reqUser.admin === false) {
res.status(403).json({ error: 'Not allowed' })
return
}
try {
const user = await app.locals.models.User.findByEmail(req.body.email)
if (user) {
res.status(400).json({ error: 'User already exists' })
return
}
} catch (e) {
if (e.name === 'NotFoundError') {
const userBody = {
username: uuid.v4().slice(0, 7),
email: req.body.email,
password: uuid.v4(),
}
const newUser = new app.locals.models.User(userBody)
newUser.roles = {}
newUser.roles.role = req.body.role
await newUser.save()
const transporter = nodemailer.createTransport({
SES: new AWS.SES(),
})
transporter.sendMail(
{
from: 'sebastian.mihalache@thinslices.com',
to: newUser.email,
subject: 'Hindawi Inivation',
text: 'You have been envited to join Hindawi as Editor in Chief',
html: { path: `${process.cwd()}/assets/invite.html` },
},
(err, info) => {
if (err) throw err
},
)
res.status(204).json()
}
}
})
}
module.exports = AWSBackend
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html data-editor-version="2" class="sg-campaigns" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<!--<![endif]-->
<!--[if (gte mso 9)|(IE)]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if (gte mso 9)|(IE)]>
<style type="text/css">
body {width: 600px;margin: 0 auto;}
table {border-collapse: collapse;}
table, td {mso-table-lspace: 0pt;mso-table-rspace: 0pt;}
img {-ms-interpolation-mode: bicubic;}
</style>
<![endif]-->
<style type="text/css">
body,
p,
div {
font-family: arial;
font-size: 14px;
}
body {
color: #626262;
}
body a {
color: #0088cd;
text-decoration: none;
}
p {
margin: 0;
padding: 0;
}
table.wrapper {
width: 100% !important;
table-layout: fixed;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
-moz-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
img.max-width {
max-width: 100% !important;
}
.column.of-2 {
width: 50%;
}
.column.of-3 {
width: 33.333%;
}
.column.of-4 {
width: 25%;
}
@media screen and (max-width:480px) {
.preheader .rightColumnContent,
.footer .rightColumnContent {
text-align: left !important;
}
.preheader .rightColumnContent div,
.preheader .rightColumnContent span,
.footer .rightColumnContent div,
.footer .rightColumnContent span {
text-align: left !important;
}
.preheader .rightColumnContent,
.preheader .leftColumnContent {
font-size: 80% !important;
padding: 5px 0;
}
table.wrapper-mobile {
width: 100% !important;
table-layout: fixed;
}
img.max-width {
height: auto !important;
max-width: 480px !important;
}
a.bulletproof-button {
display: block !important;
width: auto !important;
font-size: 80%;
padding-left: 0 !important;
padding-right: 0 !important;
}
.columns {
width: 100% !important;
}
.column {
display: block !important;
width: 100% !important;
padding-left: 0 !important;
padding-right: 0 !important;
margin-left: 0 !important;
margin-right: 0 !important;
}
}
</style>
<!--user entered Head Start-->
<!--End Head user entered-->
</head>
<body>
<center class="wrapper" data-link-color="#0088cd" data-body-style="font-size: 14px; font-family: arial; color: #626262; background-color: #F4F4F4;">
<div class="webkit">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="wrapper" bgcolor="#F4F4F4">
<tr>
<td valign="top" bgcolor="#F4F4F4" width="100%">
<table width="100%" role="content-container" class="outer" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<!--[if mso]>
<center>
<table><tr><td width="600">
<![endif]-->
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="width: 100%; max-width:600px;" align="center">
<tr>
<td role="modules-container" style="padding: 0px 0px 0px 0px; color: #626262; text-align: left;" bgcolor="#F4F4F4" width="100%"
align="left">
<table class="module preheader preheader-hide" role="module" data-type="preheader" border="0" cellpadding="0" cellspacing="0"
width="100%" style="display: none !important; mso-hide: all; visibility: hidden; opacity: 0; color: transparent; height: 0; width: 0;">
<tr>
<td role="module-content">
<p>This is the preheader text.</p>
</td>
</tr>
</table>
<table class="module" role="module" data-type="text" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;">
<tr>
<td style="padding:0px 0px 0px 0px;" height="100%" valign="top" bgcolor="">
<div style="text-align: right;">
<span style="font-family:verdana,geneva,sans-serif;">
<span style="font-size:10px;">Email not displaying correctly?
<a href="[weblink]">View it</a> in your browser.</span>
</span>
</div>
</td>
</tr>
</table>
<table class="module" role="module" data-type="text" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;">
<tr>
<td style="padding:34px 23px 34px 23px;background-color:#ffffff;" height="100%" valign="top" bgcolor="#ffffff">
<h1 style="text-align: center;">
<span style="color:#2D2D2D;">You have been envited to join Hindawi as Editor in Chief</span>
</h1>
<div style="text-align: center;">Please confirm your invitation by clicking on the button bellow</div>
</td>
</tr>
</table>
<table border="0" cellPadding="0" cellSpacing="0" class="module" data-role="module-button" data-type="button" role="module"
style="table-layout:fixed" width="100%">
<tbody>
<tr>
<td align="center" bgcolor="#ffffff" class="outer-td" style="padding:0px 0px 51px 0px;background-color:#ffffff">
<table border="0" cellPadding="0" cellSpacing="0" class="button-css__deep-table___2OZyb wrapper-mobile"
style="text-align:center">
<tbody>
<tr>
<td align="center" bgcolor="#1795CF" class="inner-td" style="-webkit-border-radius:0px;-moz-border-radius:0px;border-radius:0px;font-size:15px;text-align:center;background-color:inherit">
<a style="background-color:#1795CF;height:px;width:px;font-size:15px;line-height:px;font-family:Helvetica, Arial, sans-serif;color:#ffffff;padding:14px 56px 13px 56px;text-decoration:none;-webkit-border-radius:0px;-moz-border-radius:0px;border-radius:0px;border:1px solid #32A9D6;display:inline-block"
href="" target="_blank">CONFIRM INVITATION</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
<!--[if mso]>
</td></tr></table>
</center>
<![endif]-->
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</center>
</body>
</html>
\ No newline at end of file
......@@ -6893,6 +6893,10 @@ nodemailer@^4.0.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-4.4.1.tgz#ce480eb3db7b949b3366e301b8f0af1c1248025e"
nodemailer@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-4.4.2.tgz#f215fb88e8a1052f9f93083909e116d2b79fc8de"
nomnom@~1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.6.2.tgz#84a66a260174408fc5b77a18f888eccc44fb6971"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment