From 57aad0a2a92534ca777e2a6d53c836e227244d4f Mon Sep 17 00:00:00 2001 From: bibif5 Date: Tue, 26 Nov 2019 23:57:05 +0000 Subject: [PATCH 1/3] CONTACT PAGE ADDED In this commit I added css to the contact page and I also added functionality to it by adding a form. The form is sent as an email to the companies gmail with the customers contact details and query. The changes made here are that the css has been added. A form was also added and I made use of the nodeMailer function. --- index.js | 21 ++++++++- modules/mailer.js | 34 +++++++++++++-- public/ContactPage.css | 89 ++++++++++++++++++++++++++++++++++++++ public/home.css | 4 +- views/ContactUs.handlebars | 48 +++++++++++++++----- views/home.handlebars | 2 +- 6 files changed, 180 insertions(+), 18 deletions(-) create mode 100644 public/ContactPage.css diff --git a/index.js b/index.js index 5d2977e..6a480ab 100644 --- a/index.js +++ b/index.js @@ -158,14 +158,33 @@ router.get('/about', async ctx => { } }) -router.get('/contact', async ctx => { +router.get('/ContactUs', async ctx => { try { + const data= {} await ctx.render('ContactUs') } catch (err) { await ctx.render('error', { message: err.message }) + + } }) +router.post('/ContactUs', koaBody, async ctx => { + + try{ + //extracts data from request + const fullName = ctx.request.body.fullName + const email2 = ctx.request.body.email2 + const phone = ctx.request.body.phone + const userMessage = ctx.request.body.userMessage + + await Mailer.emailContact(fullName, email2, phone, userMessage) + ctx.redirect('/ContactUs?msg=Your query has been sent') + + } catch (err){ + await ctx.render('error', { message: err.message }) + } +}) /** * The user registration page. diff --git a/modules/mailer.js b/modules/mailer.js index c8e3fa7..924c7df 100644 --- a/modules/mailer.js +++ b/modules/mailer.js @@ -2,12 +2,13 @@ Sources: https://www.w3schools.com/nodejs/nodejs_email.asp https://www.youtube.com/watch?v=FbDRGpB2eJ8 - */ +*/ 'use strict' const nodemailer = require('nodemailer') const crypto = require('crypto') +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; const createHash = function(userString) { if (userString === '' || userString === undefined) throw new Error('String cannot be empty.') @@ -42,8 +43,35 @@ const sendMail = function(toAddress, link, userMessage) { } +const emailContact = function(fullName, email2, phone, userMessage) { + const mailText = (fullName, email2, phone, userMessage) + + const transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: 'filesharingproject2@gmail.com', + pass: 'passpasspass' + } + }) + const mailOptions = { + from: 'filesharingproject2@gmail.com', + to: 'filesharingproject3@gmail.com', + subject: 'Customer Query', + text: (mailText) + } + + transporter.sendMail(mailOptions, (error, info) => { + if (error) { + console.log(error) + } else { + console.log(`Email sent: ${info.response}`) + } + }) + +} + module.exports = { sendMail, createHash, -} - + emailContact, + } \ No newline at end of file diff --git a/public/ContactPage.css b/public/ContactPage.css new file mode 100644 index 0000000..2292b08 --- /dev/null +++ b/public/ContactPage.css @@ -0,0 +1,89 @@ +body { + font-family: sans-serif; + margin: 0; + padding: 0; +} + +header { + position: relative; + border-bottom: 10px solid #11B8FF; + margin-bottom: 5px; + padding: 13px 0; + } + + h1 { + + text-align: center; + font-size: 60px; + margin-top: 50px; + margin-bottom: 25px; + padding: 13px 0; + } + +p { + /*float: left;*/ + text-align: center; + font-size: 15px; +} + +#contacttxt{ + text-align:left; + align-content: center; + margin:10px 0; + background: rgba(red, green, blue, alpha); + border-radius: 2px; + font-family: 'Permanent Marker', cursive; + font-size: 15px; + font-weight: bold; + width: 25% +} + + +.wrapper{ + width:1170px; + margin: auto; +} + +/*#logo { + position: absolute; + left: 30px; + height: 125px; + width: auto; +}*/ + +#logo { + position: absolute; + margin-top: 0px; + width: 200px; + height: auto; + +} + +.nav-bar{ + float:right; + list-style:none; + margin-top: 30px; +} + +.nav-area li{ + display: inline-block; + +} + +.nav-area li a{ + color:white; + text-decoration: none; + padding: 5px 20px; + font-family:'Roboto', sans-serif; + font-size: 25px; + transition: 0.8s; + +} + + + +.nav-area li a:hover{ + background:white; + color:#333; + +} \ No newline at end of file diff --git a/public/home.css b/public/home.css index 7723463..8d51631 100644 --- a/public/home.css +++ b/public/home.css @@ -52,8 +52,8 @@ header{ width: 200px; float:left; height: auto; - -} + +} .welcome-text{ position: absolute; diff --git a/views/ContactUs.handlebars b/views/ContactUs.handlebars index b513aeb..54477c7 100644 --- a/views/ContactUs.handlebars +++ b/views/ContactUs.handlebars @@ -4,25 +4,51 @@ Contact Us | Safe Share - + - - + + + -\ + + +
+ +

Contact Safe Share

-

-
- - - \ No newline at end of file + +
+ + + +
+ +

+

+ +

+

+ +

+

+ +

+

+

+ +
+ + + + + \ No newline at end of file diff --git a/views/home.handlebars b/views/home.handlebars index f92790e..9afd4aa 100644 --- a/views/home.handlebars +++ b/views/home.handlebars @@ -20,7 +20,7 @@ From 72c2c58f2b15abb5247d74daf738948504a86578 Mon Sep 17 00:00:00 2001 From: bibif5 Date: Thu, 28 Nov 2019 10:07:40 +0000 Subject: [PATCH 2/3] About us page css added and delete functionality added Added css for the about us page. Connected the delete button to the delete record function This allows the user to delete files. It has also made About us page look more visually appealing. --- index.js | 18 +++++++++-- modules/upload.js | 22 +++++++++++++- public/{ContactPage.css => ContactAbout.css} | 19 ++++-------- views/AboutUs.handlebars | 32 ++++++++++++-------- views/ContactUs.handlebars | 2 +- views/myfiles.handlebars | 10 +++--- views/upload.handlebars | 9 ++++-- 7 files changed, 75 insertions(+), 37 deletions(-) rename public/{ContactPage.css => ContactAbout.css} (83%) diff --git a/index.js b/index.js index 900e26d..f19df85 100644 --- a/index.js +++ b/index.js @@ -62,8 +62,19 @@ router.get('/', async ctx => { router.get('/myfiles', async ctx => { try { if(ctx.session.authorised !== true) return ctx.redirect('/login?msg=you need to log in') + + const file = await new File(dbName) + const data = {} + if(ctx.query.del) { + data.name = ctx.query.name + data.ex = ctx.query.ex + + const fileName = data['name'] + + await file.deleteRecord(fileName) - await new File(dbName) + await file.delFromDir(path) + } // await ctx.render('myfiles') const display = await new User(dbName) await display.UserFileDisplay(ctx, dbName, Database) @@ -87,7 +98,9 @@ router.post('/myfiles', koaBody, async ctx => { const date = ctx.request.files._file.lastModifiedDate // eslint-disable-next-line prefer-template const targetPath = '/' + userName + '/' + nameExt - + console.log(extension) + console.log(nameExt) + console.log(nameClean) const file = await new File(dbName) await file.upload(extension, targetPath, nameClean, size, date) @@ -276,5 +289,6 @@ router.get('/download/:usrName/:name', async ctx => { } }) + app.use(router.routes()) module.exports = app.listen(port, async() => console.log(`listening on port ${port}`)) diff --git a/modules/upload.js b/modules/upload.js index ed96402..aa08f2f 100644 --- a/modules/upload.js +++ b/modules/upload.js @@ -4,7 +4,6 @@ const fs = require('fs-extra') const mime = require('mime-types') const sqlite = require('sqlite-async') - module.exports = class File { constructor(dbName = ':memory:') { @@ -58,6 +57,16 @@ module.exports = class File { throw err } } + async delFromDir(path) { + try { + // eslint-disable-next-line prefer-template + targetPath = 'private/' + targetPath + fs.unlinkSync(path) + console.log('File deleted from server') + } catch(err) { + throw err + } + } async generateLink(filename, username, fullLink) { try { @@ -82,4 +91,15 @@ module.exports = class File { } } + async deleteRecord(fileName) { + try { + const sql = `DELETE FROM Files + WHERE FileName = '${fileName}'` + const data = await this.db.run(sql) + + } catch (err) { + throw err + } + } + } diff --git a/public/ContactPage.css b/public/ContactAbout.css similarity index 83% rename from public/ContactPage.css rename to public/ContactAbout.css index 2292b08..d3a7fa0 100644 --- a/public/ContactPage.css +++ b/public/ContactAbout.css @@ -23,7 +23,7 @@ header { p { /*float: left;*/ text-align: center; - font-size: 15px; + font-size: 20px; } #contacttxt{ @@ -44,13 +44,6 @@ p { margin: auto; } -/*#logo { - position: absolute; - left: 30px; - height: 125px; - width: auto; -}*/ - #logo { position: absolute; margin-top: 0px; @@ -65,13 +58,13 @@ p { margin-top: 30px; } -.nav-area li{ +.nav-bar li{ display: inline-block; } -.nav-area li a{ - color:white; +.nav-bar li a{ + color:#11B8FF; text-decoration: none; padding: 5px 20px; font-family:'Roboto', sans-serif; @@ -82,8 +75,8 @@ p { -.nav-area li a:hover{ - background:white; +.nav-bar li a:hover{ + background:#11B8FF; color:#333; } \ No newline at end of file diff --git a/views/AboutUs.handlebars b/views/AboutUs.handlebars index f94f6f4..e7a3161 100644 --- a/views/AboutUs.handlebars +++ b/views/AboutUs.handlebars @@ -6,24 +6,30 @@ About Us | Safe Share - + -

About Safe Share

- -
-

Safe Share is a website which allows logged in users to upload files to the server.
You can email a link to these files to your friends who can use this to download them.

-
+
+ + +
- + +
+

About Safe Share

+
- \ No newline at end of file +
+

Safe Share is a website which allows logged in users to upload files to the server.
You can email a link to these files to your friends who can use this to download them.

+
+ + \ No newline at end of file diff --git a/views/ContactUs.handlebars b/views/ContactUs.handlebars index 54477c7..12b37db 100644 --- a/views/ContactUs.handlebars +++ b/views/ContactUs.handlebars @@ -6,7 +6,7 @@ Contact Us | Safe Share - + diff --git a/views/myfiles.handlebars b/views/myfiles.handlebars index 4797ac1..1dbdf57 100644 --- a/views/myfiles.handlebars +++ b/views/myfiles.handlebars @@ -5,7 +5,7 @@ Share Drive - + @@ -125,9 +125,11 @@ {{this.Size}}KB {{this.FileType}} - + + + diff --git a/views/upload.handlebars b/views/upload.handlebars index 4aa4b04..a358803 100644 --- a/views/upload.handlebars +++ b/views/upload.handlebars @@ -25,8 +25,6 @@ - -