Skip to content
Permalink
Browse files
Fix handlebars subpages
  • Loading branch information
czarniek committed Dec 1, 2019
1 parent 1544322 commit 9af24c4966d4e99ea162f674ae4d1cf5e67581fa
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 152 deletions.
@@ -24,7 +24,7 @@ const router = new Router()
/* CONFIGURING THE MIDDLEWARE */
app.keys = ['darkSecret']
app.use(staticDir('public'))
app.use(staticDir('private')) //TODO: is this considered 'not public'?
app.use(staticDir('private'))
app.use(bodyParser())
app.use(session(app))
app.use(views(`${__dirname}/views`, { extension: 'handlebars' }, {map: { handlebars: 'handlebars' }}))
@@ -75,6 +75,8 @@ router.get('/myfiles', async ctx => {
} 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()
}
@@ -102,14 +104,6 @@ router.post('/myfiles', koaBody, async ctx => {
}
})

router.get('/shared', async ctx => {

try {
await ctx.render('shared')
} catch (err) {
await ctx.render('error', { message: err.message })
}
})

router.get('/about', async ctx => {
try {
@@ -202,17 +196,6 @@ router.get('/account', async ctx => {
}
})

router.post('/account', koaBody, async ctx => {
try {
const user = await new User(dbName)
await user

} catch (err) {
await ctx.render('error', { message: err.message })
}
})


router.get('/logout', async ctx => {
ctx.session.authorised = null
ctx.redirect('/')
@@ -246,7 +229,7 @@ router.post('/transfer', koaBody, async ctx => {

//TODO: username passed in email
//Send the link in email
await Mailer.sendMail(email, link, userMessage)
// await Mailer.sendMail(email, link, userMessage)

ctx.redirect('/myfiles?msg=Your file has been transfered!')

@@ -262,6 +245,8 @@ router.get('/download/:usrName/:name', async ctx => {
const fileName = ctx.params.name
const userName = ctx.params.usrName

// console.log(ctx.request.url)

file = await new File(dbName)

const fileData = await file.getFileInfo(fileName, userName)
@@ -290,7 +275,7 @@ router.post('/download', async ctx => {
await file.updateValue(fileHash)
}

return ctx.redirect('/')
return ctx.redirect('back')
} catch (err) {
await ctx.render('error', { message: err.message })
} finally {
@@ -124,10 +124,9 @@ module.exports = class File {

async generateLink(_fileName, username, fullLink) {
try {
//TODO: Only search table belonging to specific user
const sql = `SELECT FilePath, FileHash FROM Files
WHERE FileName LIKE '${_fileName}' OR
FileHash LIKE '${_fileName}'`
FileHash LIKE '${_fileName}' AND user LIKE '${username}'`

const data = await this.db.all(sql)
let link = data[0]['FilePath']
@@ -160,11 +159,9 @@ module.exports = class File {

async getFileInfo(_fileName, _userName) {
try {
_userName = ''
console.log(_userName)
//TODO: Only search table belonging to specific user
const sql = `SELECT * FROM Files
WHERE FileHash LIKE '${_fileName}' OR FileName LIKE '${_fileName}'`
WHERE FileHash LIKE '${_fileName}' OR
FileName LIKE '${_fileName}' AND user LIKE '${_userName}'`

const data = await this.db.all(sql)

@@ -87,7 +87,6 @@ module.exports = class User {
WHERE user LIKE "%${username}%"`
let querystring = ''

console.log(ctx.query.q)
if (ctx.query !== undefined && ctx.query.q !== undefined) {
sql = `SELECT user, FileName, FileType, FilePath, Size, Date, ExpDate FROM Files
WHERE upper(FileName) LIKE "%${ctx.query.q}%"
@@ -102,12 +101,7 @@ module.exports = class User {
}
const db = await Database.open(dbName)
let data = await db.all(sql)
console.log(data)
await db.close()
//console.log('THIS IS A TEST SPACEEEEEE')
//console.log('THIS IS A TEST SPACEEEEEE')
//console.log('THIS IS A TEST SPACEEEEEE')
//console.log('THIS IS A TEST SPACEEEEEE')
if (ctx.query !== undefined && ctx.query.q !== undefined) {
data = data.filter( data => {
if (data.user === username) return true
@@ -19,8 +19,7 @@
<nav id='nav2'>
<ul>
<li><a href="/myfiles">My Files</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact Us</a></li>
<li><a class='active' href="/account">Account</a></li>
</ul>
</nav>
<section id='UserInformation'>
@@ -20,7 +20,6 @@
<nav id='nav2'>
<ul>
<li><a href="/myfiles">My Files</a></li>
<li><a href="/shared">Shared with me</a></li>
<li><a href="/account">Account</a></li>
</ul>
</nav>

This file was deleted.

@@ -41,7 +41,6 @@
<nav id='nav2'>
<ul>
<li ><a class='active' href="/myfiles">My Files</a></li>
<li><a href="/shared">Shared with me</a></li>
<li><a href="/account">Account</a></li>
</ul>
</nav>
@@ -99,10 +98,10 @@
<p id="msg">{{msg.msg}}</p>
{{/if}}

<span id='twoButtons'>
{{!-- <span id='twoButtons'>
<button type="button" class='button' ><img class='smlImg' src='images/gridFull.png' /></button>
<button type="button" class='button'><img class='smlImg' src='images/sort.png' /></button>
</span>
</span> --}}


</section>
@@ -34,7 +34,6 @@
<nav id='nav2'>
<ul>
<li><a href="/myfiles">My Files</a></li>
<li><a href="/shared">Shared with me</a></li>
<li><a href="/account">Account</a></li>
</ul>
</nav>

This file was deleted.

0 comments on commit 9af24c4

Please sign in to comment.