Skip to content

imageshtml #15

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Binary file added images/CVing.docx
Binary file not shown.
Binary file added images/back.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/business.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/businesspic.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/businesspic1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/businesspic2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/firstnew.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new11.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new4img.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new5.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new5img.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new6.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new6img.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new7.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new7img.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/newspic.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/secondnew.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sports1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sports2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sports3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thirdnew.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
}
}


}




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

var sqlite = require('sqlite-async');


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 uploadart {

constructor(dbName = ':memory:') {
return (async() => {
this.db = await sqlite.open(dbName)
const sql = ('CREATE TABLE IF NOT EXISTS Article (First_Name TEXT PRIMARY KEY, Last_name TEXT, Category TEXT ,Title TEXT, Text TEXT)')
await this.db.run(sql)
return this
})()
}


async checkarticle(First_Name,Last_name,Category,Title,Text) {
try {
if(First_Name.length === 0) throw new Error('Field Required')
if(Last_name.length === 0) throw new Error('Field Required')
if(Title.length === 0) throw new Error('Field Required')
if(Text.length === 0) throw new Error('Field Required')
let sql = `SELECT COUNT(First_Name) as records FROM Article WHERE First_Name="${First_Name}";`
const data = await this.db.get(sql)
if(data.records !== 0) throw new Error(`Article "${First_Name}" already exists`)
sql = `INSERT INTO Article(First_Name, Last_name, Category ,Title, Text) VALUES("${First_Name}", "${Last_name}", "${Category}" , "${Title}", "${Text}")`
await this.db.run(sql)
return true
} catch(err) {
throw err
}
}


}




16 changes: 16 additions & 0 deletions public/css/business.css
Expand Up @@ -59,6 +59,22 @@ body {

}

.card {

box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
}


.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}


.container {
padding: 2px 16px;
}


.sidenav a {
color: white;
Expand Down
16 changes: 16 additions & 0 deletions public/css/careers.css
Expand Up @@ -19,6 +19,22 @@

}

.card {

box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
}


.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}


.container {
padding: 2px 16px;
}

.navbar a:hover {
background-color: #ddd;
color: black;
Expand Down
11 changes: 11 additions & 0 deletions public/css/entertainment.css
Expand Up @@ -19,6 +19,17 @@

}

.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.container {
padding: 2px 16px;
}

.navbar a:hover {
background-color: #ddd;
color: black;
Expand Down
39 changes: 39 additions & 0 deletions public/css/homepage.css
Expand Up @@ -126,6 +126,45 @@ a.logout{

}

.boxed {
width: 320px;
padding: 10px;
border: 5px solid gray; ;
}

.b {
display: inline-block;
position: center;
margin: 10%;
float: left;
height: 400px 3;
background-color: lightgrey;
}
.column3 {
column-rule-style: solid;
width: 100%;
column-count: 2;


background-color: lightgrey;
columns: 100px 1;

}

table, th, td {
position: left;
table-layout: fixed;
width: 100%;
border: 1px solid grey;
background-color: lightgrey;
text-align: left;
border-collapse: collapse

}




section2 {
float: left;
width: 25%;
Expand Down
16 changes: 16 additions & 0 deletions public/css/lifeandstyle.css
Expand Up @@ -19,6 +19,22 @@

}

.card {

box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
}


.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}


.container {
padding: 2px 16px;
}

.navbar a:hover {
background-color: #ddd;
color: black;
Expand Down
15 changes: 15 additions & 0 deletions public/css/music.css
Expand Up @@ -13,6 +13,21 @@
text-decoration: none;

}
.card {
/* Add shadows to create the "card" effect */
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
}

/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}

/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}

.navbar a.right {
float: right;
Expand Down