Merge branch 'master' of https://bitbucket.org/cliffbreak/shakes-fidget
This commit is contained in:
commit
7cff726581
5 changed files with 82 additions and 8 deletions
42
index.js
42
index.js
|
@ -1,15 +1,38 @@
|
||||||
var app = require('express')()
|
var app = require('express')(),
|
||||||
var http = require('http').Server(app)
|
session = require('express-session'),
|
||||||
var request = require('request')
|
http = require('http').Server(app),
|
||||||
var exphbs = require('express-handlebars')
|
request = require('request'),
|
||||||
|
exphbs = require('express-handlebars')
|
||||||
|
|
||||||
app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.hbs'}))
|
app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.hbs'}))
|
||||||
app.set('view engine', '.hbs')
|
app.set('view engine', '.hbs')
|
||||||
|
|
||||||
|
// function checkAuth (req, res, next) {
|
||||||
|
// console.log(req.session);
|
||||||
|
|
||||||
|
// console.log('checkAuth ' + req.url);
|
||||||
|
|
||||||
|
// // don't serve /secure to those not logged in
|
||||||
|
// // you should add to this list, for each and every secure url
|
||||||
|
// // if (req.url === '/' && (!req.session || !req.session.authenticated)) {
|
||||||
|
// // res.render('unauthorised', { status: 403 });
|
||||||
|
// // return;
|
||||||
|
// // }
|
||||||
|
// next()
|
||||||
|
// }
|
||||||
|
|
||||||
|
app.use(session({ secret: 'example' }))
|
||||||
|
// app.use(checkAuth)
|
||||||
|
|
||||||
|
|
||||||
var url = 'http://192.168.178.109:1024/'
|
var url = 'http://192.168.178.109:1024/'
|
||||||
|
|
||||||
// Host the HTML File
|
// Host the HTML File
|
||||||
app.get('/', function(req, res){
|
app.get('/', function(req, res){
|
||||||
|
if(!req.session.name){
|
||||||
|
res.render('login')
|
||||||
|
return
|
||||||
|
}
|
||||||
request({
|
request({
|
||||||
url: url,
|
url: url,
|
||||||
json: true,
|
json: true,
|
||||||
|
@ -39,4 +62,15 @@ app.get('/assets/*', function(req, res){
|
||||||
res.sendFile(__dirname + req.originalUrl)
|
res.sendFile(__dirname + req.originalUrl)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post('/',function(req,res){
|
||||||
|
console.log(req);
|
||||||
|
|
||||||
|
if(req.body.name === 'Admin' && req.body.pass === '1234'){
|
||||||
|
req.session.name = req.body.name
|
||||||
|
res.end('success')
|
||||||
|
} else {
|
||||||
|
res.end('denied')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(8080)
|
app.listen(8080)
|
||||||
|
|
39
package-lock.json
generated
39
package-lock.json
generated
|
@ -215,6 +215,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
||||||
},
|
},
|
||||||
|
"crc": {
|
||||||
|
"version": "3.4.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz",
|
||||||
|
"integrity": "sha1-naHpgOO9RPxck79as9ozeNheRms="
|
||||||
|
},
|
||||||
"cryptiles": {
|
"cryptiles": {
|
||||||
"version": "3.1.2",
|
"version": "3.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz",
|
||||||
|
@ -357,6 +362,22 @@
|
||||||
"promise": "7.3.1"
|
"promise": "7.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"express-session": {
|
||||||
|
"version": "1.15.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.15.6.tgz",
|
||||||
|
"integrity": "sha512-r0nrHTCYtAMrFwZ0kBzZEXa1vtPVrw0dKvGSrKP4dahwBQ1BJpF2/y1Pp4sCD/0kvxV4zZeclyvfmw0B4RMJQA==",
|
||||||
|
"requires": {
|
||||||
|
"cookie": "0.3.1",
|
||||||
|
"cookie-signature": "1.0.6",
|
||||||
|
"crc": "3.4.4",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "1.1.2",
|
||||||
|
"on-headers": "1.0.1",
|
||||||
|
"parseurl": "1.3.2",
|
||||||
|
"uid-safe": "2.1.5",
|
||||||
|
"utils-merge": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"extend": {
|
"extend": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
|
||||||
|
@ -705,6 +726,11 @@
|
||||||
"ee-first": "1.1.1"
|
"ee-first": "1.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"on-headers": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c="
|
||||||
|
},
|
||||||
"once": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
|
@ -769,6 +795,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
|
||||||
"integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A=="
|
"integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A=="
|
||||||
},
|
},
|
||||||
|
"random-bytes": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs="
|
||||||
|
},
|
||||||
"range-parser": {
|
"range-parser": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
|
||||||
|
@ -966,6 +997,14 @@
|
||||||
"integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=",
|
"integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"uid-safe": {
|
||||||
|
"version": "2.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||||
|
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
|
||||||
|
"requires": {
|
||||||
|
"random-bytes": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"unpipe": {
|
"unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
"express-handlebars": "^3.0.0",
|
"express-handlebars": "^3.0.0",
|
||||||
|
"express-session": "^1.15.6",
|
||||||
"request": "^2.83.0"
|
"request": "^2.83.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Session Management in NodeJS using Express4.2</title>
|
<title>Session Management in NodeJS using Express4.2</title>
|
||||||
<script src="../jquery-3.3.1.min.js"></script>
|
<script src="assets/jquery-3.3.1.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var name,pass;
|
var name,pass;
|
||||||
|
@ -11,10 +11,10 @@ $(document).ready(function(){
|
||||||
/*
|
/*
|
||||||
* Perform some validation here.
|
* Perform some validation here.
|
||||||
*/
|
*/
|
||||||
$.post(window.location.href,{name:name,pass:pass},function(data){
|
$.post(window.location.href, {name:name,pass:pass}, function(data){
|
||||||
if(data==='done')
|
if(data==='success')
|
||||||
{
|
{
|
||||||
window.location.href="/admin";
|
window.location.href="/";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue