Skip to content

lifeandstyle.css #12

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
83 changes: 72 additions & 11 deletions index.js
Expand Up @@ -65,12 +65,12 @@ router.get('/', async ctx => {
}

try {
const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article;'
const sql = 'SELECT id,rtitle,Name,Stars,comment FROM reviews;'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
await db.close()
console.log(data)
await ctx.render('index', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', Article: data})
await ctx.render('index', {id: 'Identification', Name: 'creator name', Stars: 'Rating', Comment: 'message',rTitle : 'Review Title', review: data})
} catch(err) {
ctx.body = err.message
}
Expand Down Expand Up @@ -293,10 +293,10 @@ router.get('/upload', async ctx => {
})



// upload with if statement to see each new in the appropriate category

router.post('/upload', koaBody, async ctx => {
// router.post('/upload', async ctx => {

try {
const body = ctx.request.body
console.log(body)
Expand All @@ -310,12 +310,71 @@ router.post('/upload', koaBody, async ctx => {
await fs.copy(path, `public/articles/${body.image}.png`)
const sql = `INSERT INTO Article(Userid, Category, Title, Summary, Comment, Image)
VALUES("${body.userid}", "${body.category}", "${body.title}", "${body.summary}", "${body.comment}", "${body.image}");`
await db.run(sql)
await db.run(sql)
if(body.category == 'Business'){ // Category Business

const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article Where Category="Business";'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
await db.close()
return ctx.redirect('/upload?successMsg=You have successfully uploaded!')
} catch(err) {
console.log(data)
await ctx.render('Business', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', Business: data})



}else if(body.category == 'Music'){ // Category Music

const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article Where Category="Music";'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
console.log(data)
await db.close()
await ctx.render('Music', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', Music: data})


}else if(body.category == 'Entertainment'){ // Category Entertainment

const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article Where Category="Entertainment";'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
console.log(data)
await db.close()
await ctx.render('entertainment', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', enter: data})


}else if(body.category == 'Careers'){ // Category careers

const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article Where Category="Careers";'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
console.log(data)
await db.close()
await ctx.render('careers', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', careers: data})

}else if(body.category == 'Sports'){ // Category sports

const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article Where Category="Sports";'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
console.log(data)
await db.close()
await ctx.render('sports', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', sports: data})

}else if(body.category == 'Life_And_Style'){ // Category Life & Style

const sql = 'SELECT Userid, Category, Title, Summary, Comment, Image FROM Article Where Category="Life_And_Style";'
const db = await sqlite.open('./website.db')
const data = await db.all(sql)
console.log(data)
await db.close()
await ctx.render('lifeandstyle', {Userid: 'Identification', Category: 'Field of news', Title: 'Heading', Summary: 'Short description', Comment: 'Explanation', Image: 'Title for image', life: data})
}


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

})


Expand All @@ -324,17 +383,19 @@ router.post('/upload', koaBody, async ctx => {
const data = {}
data.user = ctx.session.user
await ctx.render('reviews', data)
})
});




router.post('/reviews', async ctx => {
try {
console.log(ctx.request.body)
const body = ctx.request.body
const db = await sqlite.open('./website.db')
await db.run('CREATE TABLE IF NOT EXISTS reviews (id INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT, Stars integer, comment TEXT);')
const sql = `INSERT INTO reviews (Name, stars, comment)
VALUES("${body.name}", "${body.stars}", "${body.comment}");`
await db.run('CREATE TABLE IF NOT EXISTS reviews (id INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT, Stars integer, comment TEXT, rTitle Text);')
const sql = `INSERT INTO reviews (Name, stars, comment, rTitle)
VALUES("${body.name}", "${body.stars}", "${body.comment}","${body.rTitle}");`
await db.run(sql)
await db.close()
return ctx.redirect('/reviews?successMsg=You have successfully uploaded!')
Expand Down
204 changes: 204 additions & 0 deletions lifeandstyle.css
@@ -0,0 +1,204 @@
.navbar {
overflow: hidden;
background-color: #000033;

}

.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 20px;
text-decoration: none;

}

.navbar a.right {
float: right;

}

.navbar a:hover {
background-color: #ddd;
color: black;
}
.navbar input[type=text] {
float: right;
padding: 6px;
border: none;
margin-top: 8px;
margin-right: 16px;
font-size: 17px;
}

.header {
text-align: center;
background: linear-gradient(to bottom, #ff6600 0%, #ffff00 100%);
color: #000033;

}

body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background-color: #ffff99


}

.sidenav {
height: 100%;
width: 200px;
position: absolute;
z-index: 1;
top: 0;
left: 0;
background-image: url(/images/business.png);
background-repeat: no-repeat bottom;
overflow-x: hidden;
overflow-y: hidden;
margin-top: 49px;
margin-bottom: -5000px;
padding-bottom: 5000px;

}


.sidenav a {
color: white;
padding: 14px 20px;
text-decoration: none;
display: block;


}

.sidenav a:hover {
background: #ddd;
color: black;
}


.content {
margin-left: 200px;
padding-left: 20px;
color: #000033;
}

.main {
margin-right: auto;
position:relative;
font-size: 20px;
padding: 0px 10px;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.column:after {
content: "";
display: table;
clear: both;
}


* {
box-sizing: border-box;
}


.mySlides {display: none}
img {vertical-align: middle;}

.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}

.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: #000033;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}


.next {
right: 0;
border-radius: 3px 0 0 3px;
}


.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}

.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}


.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}


.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}

.active, .dot:hover {
background-color: #717171;
}


.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}

@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}

53 changes: 53 additions & 0 deletions modules/register.js
@@ -0,0 +1,53 @@
'use strict'

var sqlite = require('sqlite-async');
let bcrypt = require('bcrypt-promise');

async function runSQL(query) {
try {
console.log(query)
let DBName = "./website.db";
const db = await sqlite.open(DBName);
const data = await db.all(query);
await db.close();
if(data.length === 1) return data[0]
return data;
} catch(err) {
throw err
}

}

module.exports = class register {

constructor(dbName = ':memory:') {
return (async() => {
this.db = await sqlite.open(dbName)
const sql = ('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, pass TEXT);')
await this.db.run(sql)
return this
})()
}


async checkregister(user,pass) {
try {
if(user.length === 0) throw new Error('Field Required')
if(pass.length === 0) throw new Error('Field Required')
let sql = `SELECT COUNT(id) as records FROM users WHERE user="${user}";`
const data = await this.db.get(sql)
if(data.records !== 0) throw new Error(`users "${user}" already exists`)
sql = `INSERT INTO users(user,pass) VALUES("${user}","${pass}")`
await this.db.run(sql)
return true
} catch(err) {
throw err
}
}


}