From 93e8ca189b07a294efbd2f7967153d746443ec60 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sun, 13 Jan 2019 12:10:13 -0500 Subject: [PATCH] Updated admin section of website to use template engine for the login screen and started it for the downloads page. --- README.md | 102 +++------------------------------ admin/admin.js | 35 ++++++----- admin/login/login.js | 31 +++++----- admin/posts/newPost.html | 2 + includes/html/adminHeader.html | 31 +++++++--- includes/html/header.html | 3 +- includes/includes.js | 22 +++++-- sites/admin.js | 17 ++++-- sites/projects.js | 1 + utils/utils.js | 17 ++++++ 10 files changed, 117 insertions(+), 144 deletions(-) diff --git a/README.md b/README.md index a0cdc4f..2b7ca96 100644 --- a/README.md +++ b/README.md @@ -31,67 +31,6 @@ the [Creative Commons Attribution-ShareAlike 4.0 International](https://creative unless otherwise stated. -## MYSQL Schema - -![](docs/blogSql.svg) - -```mysql -create database jrtechs_blog; - -use jrtechs_blog; - -create table users( -user_id mediumint unsigned not null AUTO_INCREMENT, -user_name varchar(60) not null, -password char(64) not null, -salt char(64) not null, -primary key(user_id) -); - -create table categories( -category_id mediumint unsigned not null AUTO_INCREMENT, -name varchar(60) not null, -url varchar(60) not null, -primary key(category_id) -); - -create table posts( -post_id mediumint unsigned not null AUTO_INCREMENT, -category_id mediumint unsigned not null, -picture_url varchar(100) not null, -published datetime not null, -name varchar(100) not null, -url varchar(100) not null, -primary key(post_id) -); - - -create table downloads( -download_id mediumint unsigned not null AUTO_INCREMENT, -file varchar(40) not null, -name varchar(40) not null, -download_count mediumint not null, -primary key(download_id) -); - -create table popular_posts( -popular_post_id mediumint unsigned not null AUTO_INCREMENT, -post_id mediumint unsigned not null, -primary key(popular_post_id) -); - -create table traffic_log( -log_id mediumint unsigned not null AUTO_INCREMENT, -url varchar(60) not null, -ip varchar(20) not null, -date datetime not null, -primary key(log_id) -); - - -grant all on jrtechs_blog.* to blog_user@localhost identified by "password"; -``` - ## Node Dependencies ```bash @@ -110,7 +49,7 @@ npm install memory-cache --save npm install request npm install nodemailer npm install nodemailer-smtp-transport - +npm install whiskers npm install node-pandoc ``` @@ -140,7 +79,8 @@ apt-get install optipng ## NGINX Configuration ``` #jrtechs.net.conf -server { +server +{ listen 80; server_name www.jrtechs.net jrtechs.net; @@ -148,7 +88,8 @@ server { return 301 https://jrtechs.net$request_uri; } -server { +server +{ listen 443 ssl http2; server_name jrtechs.net; @@ -167,38 +108,11 @@ server { } ``` -``` -#admin.jrtechs.net.conf -server { - listen 80; - server_name www.admin.jrtechs.net admin.jrtechs.net; - - # redirect http requests to https - return 301 https://admin.jrtechs.net$request_uri; -} - -server { - listen 443 ssl http2; - - server_name admin.jrtechs.net; - - ssl_certificate /etc/letsencrypt/live/admin.jrtechs.net/cert.pem; - ssl_certificate_key /etc/letsencrypt/live/admin.jrtechs.net/privkey.pem; - - location / { - proxy_pass http://localhost:8001; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } -} -``` ## Projects Sites -As I develop more projects I would like an easy way to add and host them on my website without having to create another subdomain and generate more ssl certs. I simply want the project site to be accessible under https://jrtechs.net/project_name. +As I develop more projects I would like an easy way to add and host them on my website without having to create another sub-domain and generate more ssl certs. +I simply want the project site to be accessible under https://jrtechs.net/project_name. -### State Diagrm of Plan +### State Diagram of Plan ![diagram](docs/projectsSites.svg) \ No newline at end of file diff --git a/admin/admin.js b/admin/admin.js index 73516a3..d5266e5 100644 --- a/admin/admin.js +++ b/admin/admin.js @@ -6,6 +6,8 @@ const utils = require('../utils/utils.js'); + + module.exports= { /** @@ -14,33 +16,36 @@ module.exports= * @param request * @return {*|Promise} */ - main: function(request, clientAddress) + main: function(request, clientAddress, templateContext) { return new Promise(function(resolve, reject) { + //if logged in if(request.session && request.session.user) { + templateContext.loggedIn = true; utils.getPostData(request).then(function (postData) { - console.log(postData); - Promise.all([require("./posts/newPost.js").main(postData), - require("./category/addCategory.js").main(postData), - require("./posts/editPost.js").main(postData), - require("./downloads/manageDownloads.js").main(postData)]) - .then(function(content) - { - resolve(content.join('')); - }).catch(function(error) - { - reject(error); - }); + resolve(); + // console.log(postData); + // Promise.all([require("./posts/newPost.js").main(postData), + // require("./category/addCategory.js").main(postData), + // require("./posts/editPost.js").main(postData), + // require("./downloads/manageDownloads.js").main(postData)]) + // .then(function(content) + // { + // resolve(content.join('')); + // }).catch(function(error) + // { + // reject(error); + // }); }); } else { - require("./login/login.js").main(request).then(function(html) + require("./login/login.js").main(request, clientAddress, templateContext).then(function() { - resolve(html); + resolve(); }).catch(function(err) { console.log(err); diff --git a/admin/login/login.js b/admin/login/login.js index a8da076..33a802d 100644 --- a/admin/login/login.js +++ b/admin/login/login.js @@ -15,7 +15,7 @@ const qs = require('querystring'); * @param request * @returns {Promise} */ -const processLogin = function(request, clientAddress) +const processLogin = function(request, clientAddress, templateContext) { return new Promise(function(resolve, reject) { @@ -37,10 +37,12 @@ const processLogin = function(request, clientAddress) //what actually logs in the user request.session.user = loginResult.user; console.log("user has logged in"); - resolve(""); + templateContext.goodLoginAttempt = true; + resolve(); } else { + templateContext.invalid = true; banIP(clientAddress); console.log("Invader!"); resolve("Wrong!"); @@ -110,27 +112,26 @@ module.exports= * @param request express request containing post data * @returns {Promise} resolves html of login page */ - main: function(request, clientAddress) + main: function(request, clientAddress, templateContext) { - if(isBanned(clientAddress)) + return new Promise(function(resolve, reject) { - return utils.printBannedPage(); - } - else - { - return new Promise(function(resolve, reject) + if(isBanned(clientAddress)) { - Promise.all([utils.include("./admin/login/login.html"), - require("../../sidebar/sidebar.js").main(), - processLogin(request, clientAddress)]).then(function(html) + templateContext.banned = true; + resolve(); + } + else + { + processLogin(request, clientAddress, templateContext).then(function() { - resolve(html.join('') + ""); + resolve(); }).catch(function(err) { reject(err); }) - }); - } + } + }); }, }; \ No newline at end of file diff --git a/admin/posts/newPost.html b/admin/posts/newPost.html index 35f1333..d6bd5ed 100644 --- a/admin/posts/newPost.html +++ b/admin/posts/newPost.html @@ -19,6 +19,8 @@ + +

New Post

diff --git a/includes/html/adminHeader.html b/includes/html/adminHeader.html index c40d9c3..4de2457 100644 --- a/includes/html/adminHeader.html +++ b/includes/html/adminHeader.html @@ -18,7 +18,7 @@ - + @@ -29,9 +29,23 @@ } p{font-size:18px;} + + + + + + - +