Browse Source

Moved server to use express, added stuff to admin page, and updated header

pull/4/head
jrtechs 6 years ago
parent
commit
51eafa7e08
10 changed files with 90 additions and 56 deletions
  1. +2
    -0
      README.md
  2. +20
    -11
      admin/admin.js
  3. +14
    -0
      admin/login.html
  4. +18
    -0
      admin/login.js
  5. +5
    -3
      includes/header.html
  6. +0
    -32
      posts/pages.js
  7. +5
    -3
      posts/posts.js
  8. +18
    -6
      server.js
  9. +0
    -1
      sidebar/recentPosts.js
  10. +8
    -0
      utils/sql.js

+ 2
- 0
README.md View File

@ -48,6 +48,8 @@ grant all on blog_name.* to blog_user@localhost identified by "password";
## Node Dependencies
```bash
npm install express
npm install client-sessions
npm install mysql
npm install sanitizer
npm install promise

+ 20
- 11
admin/admin.js View File

@ -13,21 +13,30 @@ module.exports=
*/
main: function(result, fileName, request)
{
result.write("<div class=\"w3-row\">");
return new Promise(function(resolve, reject)
{
result.write("<div class=\"w3-row\">");
utils.getPostData(request).then(function (postData)
if(request.session && request.session.user)
{
return require("../admin/newPost.js").main(result, postData);
}).then(function(postData)
{
return require("../admin/addCategory.js").main(result, postData);
}).then(function()
utils.getPostData(request).then(function (postData)
{
return require("../admin/newPost.js").main(result, postData);
}).then(function(postData)
{
return require("../admin/addCategory.js").main(result, postData);
}).then(function()
{
result.write("</div>");
resolve();
});
}
else
{
console.log("admin page ended");
resolve();
})
result.write("</div>");
//login page
return require("../admin/login.js").main(result, request);
}
});
}
};

+ 14
- 0
admin/login.html View File

@ -0,0 +1,14 @@
<div class="w3-container w3-dark-grey">
<h2>Login</h2>
</div>
<form class="w3-container">
<p>
<label class="w3-text-white"><b>User Name</b></label>
<input class="w3-input w3-border w3-light-grey" type="text"></p>
<p>
<label class="w3-text-white"><b>Password</b></label>
<input class="w3-input w3-border w3-light-grey" type="password"></p>
<p>
<button class="w3-btn w3-dark-grey">Login</button></p>
</form>

+ 18
- 0
admin/login.js View File

@ -0,0 +1,18 @@
const utils = require('../utils/utils.js');
const Promise = require('promise');
module.exports=
{
main: function(result, request)
{
utils.include(result, './admin/login.html');
return this.processLogin(result, request);
},
processLogin: function(result, request)
{
return new Promise(function(resolve, reject)
{
resolve();
});
}
};

+ 5
- 3
includes/header.html View File

@ -2,7 +2,7 @@
<html>
<title>Blog Template</title>
<title>Jrtechs</title>
<meta charset="UTF-8">
@ -29,8 +29,10 @@
<div class="w3-top">
<div class="w3-bar w3-dark-grey w3-card">
<a href="/" class="w3-bar-item w3-button w3-padding-large">Home</a>
<a href="/about" class="w3-bar-item w3-button w3-padding-large w3-hide-small">About</a>
<a href="/categories" class="w3-bar-item w3-button w3-padding-large w3-hide-small">Categories</a>
<a href="https://github.com/jrtechs" class="w3-bar-item w3-button w3-padding-large w3-hide-small">GitHub</a>
<a href="https://jrtechs.me" class="w3-bar-item w3-button w3-padding-large w3-hide-small">Portfolio</a>
<a href="https://www.youtube.com/channel/UCbebizd25t22-vv13_lr9_A"
class="w3-bar-item w3-button w3-padding-large w3-hide-small">Youtube</a>
</div>
</div>

+ 0
- 32
posts/pages.js View File

@ -1,32 +0,0 @@
var renderPage = function(result, requestURL)
{
return new Promise(function(resolve, reject)
{
result.write("<div class=\"w3-col l8 s12\">");
});
};
module.exports=
{
/**
* Displays a page and sidebar to users
*
* @param res
* @param fileName request url
*/
main: function(res, requestURL, request)
{
console.log("posts page");
return new Promise(function(resolve, reject)
{
renderPage(res, requestURL).then(function()
{
return require("../sidebar/sidebar.js").main(res)
}).then(function ()
{
resolve();
});
});
}
};

+ 5
- 3
posts/posts.js View File

@ -21,7 +21,6 @@ var renderPost = function(res, requestURL)
//user entered /category/name/ or /category/name
if(splitURL.length == 3 || splitURL.length == 4)
{
console.log("importante "+ requestURL)
sql.getPost(requestURL).then(function(post)
{
if(post != 0)
@ -40,7 +39,11 @@ var renderPost = function(res, requestURL)
}
else
{
console.log("error in parameters");
utils.print404(res).then(function()
{
res.write("</div>");
resolve();
});
}
});
};
@ -55,7 +58,6 @@ module.exports=
*/
main: function(res, requestURL, request)
{
console.log("posts page");
return new Promise(function(resolve, reject)
{
renderPost(res, requestURL).then(function()

+ 18
- 6
server.js View File

@ -9,9 +9,22 @@ const http = require('http');
const url = require('url');
var express = require("express");
var session = require('client-sessions');
const includes = require('./includes/includes.js');
http.createServer(function (request, res)
var app = express();
app.use(session({
cookieName: 'session',
secret: 'random_string_goes_here',
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
}));
app.use(function(request, res)
{
var q = url.parse(request.url, true);
var filename = q.pathname;
@ -39,12 +52,9 @@ http.createServer(function (request, res)
else if(urlSplit.length >= 2 && urlSplit[1] === 'admin') //top secret admin page
file = "./admin/admin.js";
else if(urlSplit.length >= 3)//single post page
else
file = "./posts/posts.js";
else //single static page?
file = "./posts/pages.js";
console.log(file);
includes.printHeader(res).then(function()
@ -59,4 +69,6 @@ http.createServer(function (request, res)
})
}
}).listen(8080);
});
http.createServer(app).listen(8080);

+ 0
- 1
sidebar/recentPosts.js View File

@ -5,7 +5,6 @@ module.exports=
{
main: function(res)
{
console.log("sidebar called");
return new Promise(function(resolve, reject)
{

+ 8
- 0
utils/sql.js View File

@ -189,5 +189,13 @@ module.exports=
});
});
},
getPage: function(name)
{
return new Promise(function(resolve, reject)
{
var q = "";
});
}
};

Loading…
Cancel
Save