Browse Source

Security commit

master
galmio 1 year ago
parent
commit
fec8fe5568
  1. BIN
      client/src/files/lighttable.pdf
  2. 11
      server/app/controllers/index.js
  3. 50
      server/app/controllers/tasks.js
  4. 25
      server/app/helpers/transporter.js
  5. 4
      server/app/middlewares/collections.js
  6. 8
      server/app/models/Collection.js
  7. 32
      server/app/server.js

BIN
client/src/files/lighttable.pdf

11
server/app/controllers/index.js

@ -0,0 +1,11 @@
const app = module.exports = require('express')();
app.get('/', (req, res) => {
res.send({msg: 'Server is up and running'})
})
app.use('/tasks', require('./tasks'))
app.all('*', (req, res) => {
res.status(404).send({msg: 'not found'})
})

50
server/app/controllers/tasks.js

@ -0,0 +1,50 @@
const app = module.exports = require('express')()
const { transporter, transport } = require('../helpers/transporter')
const { check, validationResult } = require('express-validator')
app.post('/sendemail',
[
check('name').isLength({ min: 3 }),
check('email').isEmail(),
check('message').isLength({ min: 3 })
],
async (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
res.json({ errors: errors.array })
return res.status(422).json({ errors: errors.array(), message: 'fail'})
}
const name = await req.body.name
const email = await req.body.email
const message = await req.body.message
const content = await `Name: ${name}\nEmail address: ${email}\nMessage: ${message}`
try {
} catch(err) {
if(err)
res.send(err)
}
let info = await transporter.sendMail({
from: `"MamaPats Mailer" <${transport.auth.user}>`,
to: 'migalmoreno@tutanota.com',
subject: 'New message from contact form',
text: content
}, (err, data) => {
if (err) {
res.json({ message: 'fail' })
} else {
res.json({ message: 'success' })
}
})
})
app.post('/darkmode', async(req, res) => {
res.cookie('darkTheme', 'true')
res.json({'msg': 'success'})
})
app.post('/lightmode', (req, res) => {
res.cookie('darkTheme', 'false')
res.json({'msg': 'success'})
})

25
server/app/helpers/transporter.js

@ -0,0 +1,25 @@
const nodemailer = require('nodemailer')
const creds = require('../../config')
const transport = {
host: 'mail.mamapats.com.pe',
port: 465,
secure: true,
auth: {
user: creds.USER,
pass: creds.PASS
}
}
const transporter = nodemailer.createTransport(transport)
transporter.verify((error, success) => {
if (error) {
console.log(error)
} else {
console.log('Server is ready to send messages')
}
})
module.exports.transporter = transporter
module.exports.transport = transport

4
server/app/middlewares/collections.js

@ -0,0 +1,4 @@
const mongoose = require('mongoose')
require('dotenv')
mongoose.connect("mongodb://186.64.123.227:27017/collections", { useNewUrlParser: true }, () => console.log('Connected to DB'))

8
server/app/models/Collection.js

@ -0,0 +1,8 @@
const mongoose = require('mongoose')
const CollectionSchema = mongoose.Schema({
name: {
type: String,
required: true
},
})

32
server/app/server.js

@ -0,0 +1,32 @@
const express = require('express')
const path = require('path')
const cookieParser = require('cookie-parser')
const routes = require('./controllers')
const collections = require('./middlewares/collections')
// Constants
const PORT = process.env.PORT || 4000;
const HOST = '0.0.0.0'
const CLIENT_BUILD_PATH = path.join(__dirname, '../../client/build')
// Express app
const app = express()
// Cookie parser middlware
app.use(cookieParser())
// Static files middleware
app.use(express.static(CLIENT_BUILD_PATH))
// Body parser middleware
app.use(express.json())
// Routes middleware
app.use('/api', routes)
app.get('*', (req, res) => {
res.sendFile(path.join(CLIENT_BUILD_PATH, 'index.html'))
})
app.listen(PORT, HOST, () => console.log(`App running on http://${HOST}:${PORT}`))
Loading…
Cancel
Save