Skip to content

carrers.handlebars #17

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
156 changes: 156 additions & 0 deletions careers.handlebars
@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Local News - Careers</title>
<link href="./css/careers.css" type="text/css" rel="stylesheet">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<div class="navbar">
<a href="/">HOME</a>
<a href="/business">BUSINESS</a>
<a href="/lifeandstyle">LIFE & STYLE</a>
<a href="/careers">CAREERS</a>
<a href="/sports">SPORTS</a>
<a href="/music">MUSIC</a>
<a href="/entertainment">ENTERTAINMENT</a>
<a href="/upload">UPLOAD</a>
<a href="/logout" class="right"> LOGOUT &#129154;</a>
<a href="/search">SEARCH</a>
</div>

<div class="header">
<h1> CAREERS </h1>
</div>
<div class="content">
<div class="sidenav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>

<div class="topcarrersnews">
<h2> &#9654 TOP CAREERS NEWS </h2>


<div class="main">
<div class="column" style="background-color:#fff4ff;">
<img src="images/sports1.png" alt="Avatar" class="image" style="width:100%;height:300px;">
<a href="#" >Description for the 1 article </a>
</div>

<div class="column" style="background-color:#fff4ff;">
<img src="images/sports2.png" alt="Avatar" class="image" style="width:100%;height:300px;">
<a href="#" >Description for the 2 article </a>
</div>

<div class="column" style="background-color:#fff4ff;">
<img src="images/sports3.png" alt="Avatar" class="image" style="width:100%;height:300px;">
<a href="#" >Description for the 3 article </a>
</div>

<div class="column" style="background-color:#fff4ff;">
<img src="images/sports1.png" alt="Avatar" class="image" style="width:100%;height:300px;">
<a href="#" >Description for the 4 article </a>
</div>

<div class="column" style="background-color:#fff4ff;">
<img src="images/sports2.png" alt="Avatar" class="image" style="width:100%;height:300px;">
<a href="#" >Description for the 5 article </a>
</div>

<div class="column" style="background-color:#fff4ff;">
<img src="images/sports3.png" alt="Avatar" class="image" style="width:100%;height:300px;">
<a href="#" >Description for the 6 article </a>
</div>
</div>



<div class="slideshow-container">
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="/images/businesspic.jpg" style="width:100%"; >
<div class="text">Business new 1</div>
</div>

<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="/images/businesspic1.jpg" style="width:100%"; >
<div class="text">Business new 2</div>
</div>

<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img src="/images/businesspic2.jpg" style="width:100%"; >
<div class="text">Business new 3</div>
</div>

<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>

</div>
<br>

<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>

<script>
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
showSlides(slideIndex += n);
}

function currentSlide(n) {
showSlides(slideIndex = n);
}

function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}

</script>

</div>
</body>

<footer id="mobile-footer" >
<div id="mobile-menu">
<div id="mobile-footer-container">
<div class="mobile-link">
<a href="/reviews" class="text-center">Reviews</a>
</div>
<div class="mobile-link">
<a href="/contact" class="text-center">Contact Us</a>
</div>
</div>
</div>
<div id="mobile-footer-close">
<button id="mobile-footer-btn">
<div class="mobile-btn-close is-rotating-back">
<span></span>
</div>
</button>
</div>
</footer>

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
}
}


}