4
1
Fork 0

Fix Login

This commit is contained in:
Simon Giesel 2018-02-20 02:50:03 +01:00
parent 7cff726581
commit 4eef658e32
2 changed files with 16 additions and 27 deletions

View file

@ -1,28 +1,17 @@
var app = require('express')(),
session = require('express-session'),
http = require('http').Server(app),
bodyParser = require('body-parser'),
request = require('request'),
exphbs = require('express-handlebars')
app.engine('.hbs', exphbs({defaultLayout: 'single', extname: '.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)
app.use(session({ resave: true, saveUninitialized: false, secret: '62gzrhufijw' }))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
var url = 'http://192.168.178.109:1024/'
@ -37,8 +26,8 @@ app.get('/', function(req, res){
url: url,
json: true,
auth: {
user: 'Simon',
pass: 'password'
user: req.session.name,
pass: req.session.pass
}
}, function(error, response, body){
var data = []
@ -63,14 +52,16 @@ app.get('/assets/*', function(req, res){
})
app.post('/',function(req,res){
console.log(req);
if(req.body.name === 'Admin' && req.body.pass === '1234'){
if(
req.body.name === 'Simon' && req.body.pass === 'password' ||
req.body.name === 'USER2' && req.body.pass === 'rfcgvhbßä06'
){
req.session.name = req.body.name
res.end('success')
req.session.pass = req.body.pass
res.end('true')
} else {
res.end('denied')
res.end()
}
});
})
app.listen(8080)

View file

@ -12,10 +12,8 @@ $(document).ready(function(){
* Perform some validation here.
*/
$.post(window.location.href, {name:name,pass:pass}, function(data){
if(data==='success')
{
window.location.href="/";
}
if(data === 'true')
window.location.href= '/';
});
});
});