Skip to content
Permalink
Browse files
Merge pull request #18 from georgiak/contactPage2
Contact page2
  • Loading branch information
czarniek committed Dec 1, 2019
2 parents 7d7003f + 29cd581 commit 348274207c5e448368b10e5d6f37ab7bc0b3769a
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 41 deletions.
@@ -61,27 +61,40 @@ router.get('/', async ctx => {
// eslint-disable-next-line max-lines-per-function
router.get('/myfiles', async ctx => {
try {
if(ctx.session.authorised !== true) return ctx.redirect('/login?msg=You need to log in')
if(ctx.session.authorised !== true) return ctx.redirect('/login?msg=you need to log in')

const file = await new File(dbName)
const data = {}

file = await new File(dbName)
if(ctx.query.del) {
data.name = ctx.query.name
data.ex = ctx.query.ex

const fileName = data['name']

await file.delFromDir(path)
await file.deleteRecord(fileName)
}

file = await new File(dbName)
await file.deleteExpired()
user = await new User(dbName)
const username = ctx.session.userName
//console.log(username)
await user.UserFileDisplay(ctx, dbName, Database,username)
// console.log(data)

} catch(err) {
} catch (err) {
await ctx.render('error', {message: err.message})
} finally {
if(ctx.session.authorised !== true) return ctx.redirect('/login?msg=You need to log in')

file.tearDown()
user.tearDown()
}

})



router.post('/myfiles', koaBody, async ctx => {
try {
@@ -113,14 +126,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.
@@ -283,5 +315,6 @@ router.post('/download', async ctx => {
}
})


app.use(router.routes())
module.exports = app.listen(port, async() => console.log(`listening on port ${port}`))
@@ -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.')
@@ -54,8 +55,35 @@ const sendMail = function(toAddress, link, userMessage) {
}


module.exports = {
sendMail,
createHash
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,
}
@@ -141,6 +141,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 countItems() {
try {
@@ -172,6 +182,18 @@ module.exports = class File {
throw err
}
}

async deleteRecord(fileName) {
try {
const sql = `DELETE FROM Files
WHERE FileName = '${fileName}'`
const data = await this.db.run(sql)

} catch (err) {
throw err
}
}

/* istanbul ignore next */
async tearDown() {
await this.db.close()
@@ -0,0 +1,82 @@
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: 20px;
}

#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;
margin-top: 0px;
width: 200px;
height: auto;

}

.nav-bar{
float:right;
list-style:none;
margin-top: 30px;
}

.nav-bar li{
display: inline-block;

}

.nav-bar li a{
color:#11B8FF;
text-decoration: none;
padding: 5px 20px;
font-family:'Roboto', sans-serif;
font-size: 25px;
transition: 0.8s;

}



.nav-bar li a:hover{
background:#11B8FF;
color:#333;

}
@@ -52,8 +52,8 @@ header{
width: 200px;
float:left;
height: auto;
}

}

.welcome-text{
position: absolute;
@@ -0,0 +1,44 @@
'use strict'

const Uploads = require('../modules/upload.js')

describe('deleteRecord()', () => {
test('the deletd file does not still exist in db', async done=>{
expect.assertions(1)
const todo = await new Uploads()

await expect(todo.deletedRecord('lab5')).toBeNull()
done()

})
})


describe('upload()', () => {
test('File Name missing', async done => {
expect.assertions(1)
const todo = await new Uploads()
await expect(todo.upload(
'png','',200,'Wed 20/20/19 15:20:20','path','Userpath')).rejects.toEqual(Error('String cannot be empty.'))
done()
})

test('File Not bigger than a GB', async done => {
expect.assertions(1)
const todo = await new Uploads()
await expect(todo.upload(
'png','name',1073741824,'Wed 20/20/19 15:20:20',
'path','Userpath')).rejects.toEqual(Error('Size cannot be equal or greater than a GB'))
done()
})

test('File Name string too long', async done => {
expect.assertions(1)
const todo = await new Uploads()
await expect(todo.upload(
'png','K8DbQxhva2qECr7urmCOVOayGnf6OUh2MCjYC9VaO04m9SXLui',
10750,'Wed 20/20/19 15:20:20','path','Userpath')).rejects.toEqual(Error('String size too big'))
done()
})

})
@@ -6,25 +6,30 @@
<title>About Us | Safe Share</title>
<meta name="description" content="form to add new books">
<meta name="author" content="Mark Tyers">
<link href = "home.css" type = "text/css" rel = "stylesheet"/>
<link rel = "stylesheet" href="ContactAbout.css" type = "text/css" />
<!--<link href="https://fonts.googleapis.com/css?family=Acme|Roboto&display=swap" rel="stylesheet"> -->

</head>

<body>

<h1> About Safe Share </h1>

<section>
<p> Safe Share is a website which allows logged in users to upload files to the server. <br>You can email a link to these files to your friends who can use this to download them. </p>
</section>
<header>
<a href='/'><img id='logo' src='images/logo.png' alt='Share Drive logo' /></a>

<section>

<ul class = "nav-bar">
<li> <a href="#"> Home</a></li>
<li> <a href="/myfiles"> Files</a></li>
<li> <a href="#">Contact Us</a></li>
<li> <a href="/logout">Logout</a></li>
<li><a href="/account">Account</a></li>
</ul>
<ul class = "nav-bar">
<li> <a href="/"> Home</a></li>
<li> <a href="/myfiles"> Files</a></li>
<li> <a href="/ContactUs">Contact Us</a></li>
<li> <a href="/logout">Logout</a></li>
</ul>
</section>
<h1> About Safe Share </h1>
</header>

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

</body>

0 comments on commit 3482742

Please sign in to comment.