From c8499b16fa6b44c8d9927f5f8ff11d25811af967 Mon Sep 17 00:00:00 2001 From: renato costa Date: Mon, 2 Dec 2019 06:13:08 +0000 Subject: [PATCH] Contact us page created and .txt with email credentials --- email credentials.txt | 2 + index.js | 48 +++++++++++++++++- views/contact.handlebars | 102 +++++++++++++++++++++++++++++++++++++++ views/index.handlebars | 2 +- 4 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 email credentials.txt create mode 100644 views/contact.handlebars diff --git a/email credentials.txt b/email credentials.txt new file mode 100644 index 0000000..9326eb8 --- /dev/null +++ b/email credentials.txt @@ -0,0 +1,2 @@ +user: 'localnewsspp@gmail.com', +pass: 'localnewssup123' \ No newline at end of file diff --git a/index.js b/index.js index c290980..710d530 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ const sqlite = require('sqlite-async') const bcrypt = require('bcrypt-promise') const fs = require('fs-extra') const mime = require('mime-types') +const nodemailer = require('nodemailer') //const jimp = require('jimp') /* IMPORT CUSTOM MODULES */ @@ -280,4 +281,49 @@ router.post('/upload', async ctx => { } catch(err) { await ctx.render('error', {message: err.message}) } - }) \ No newline at end of file + }) + + router.get("/contact", async ctx =>{ + const data = {} + await ctx.render('contact') + }) + + + router.post('/contact', async ctx => { + + console.log(ctx.request.body) + const body = ctx.request.body + const email = body.email + const sub = body.sub + const name = body.name + const report = body.report + + var transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: 'localnewsspp@gmail.com', + pass: 'localnewssup123' + } + }); + + var mailOptions = { + + from: 'localnewsspp@gmail.com', + to: 'localnewsspp@gmail.com', + subject: sub, + text: 'Email : ' + email + '\n' + 'From :' + name + '\n' + 'Subject : ' + body.sub + '\n' + 'Message : ' + report, + + }; + + transporter.sendMail(mailOptions, function(error, info){ + if (error) { + console.log(error); + } else { + console.log('Email sent: ' + info.response); + + } + }); + + ctx.redirect('/contact?successMsg=Report sent!') + + }); \ No newline at end of file diff --git a/views/contact.handlebars b/views/contact.handlebars new file mode 100644 index 0000000..9fb6304 --- /dev/null +++ b/views/contact.handlebars @@ -0,0 +1,102 @@ + + + + + + Local News - Upload Your Own Article! +
+

LOCAL NEWS

+

TOP NEWS

+
+ + + + + + + +
+
+
+

Report a Technical Error

+
+ +
+
+ Your contact details +
+ +
+
+
+ + + + +
+
+
+ + + +
+
+ +
+ + +
+
+ +
+
+
+ + +
+ + + + +
+ +
+
+ + + + + + + diff --git a/views/index.handlebars b/views/index.handlebars index 61ec475..9ac5681 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -207,7 +207,7 @@ function showSlides(n) { Reviews