Skip to content

Commit

Permalink
Enhancements and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurz committed Jul 10, 2015
1 parent 5ee198b commit c0d9503
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@
e.preventDefault();
setTimeout(function(){
if(e.target.hasAttribute('data-push-state')){
history.pushState('title', {success:true}, "/success.html");
// Only works in chrome when the original login form does not exist anymore after push (or ajax)
// So either remove (or hide) the form or try to change it's action url (? - didn't test)
// Also make sure all other forms (see above) point to a different action url
// otherwise they are considered as login form too (to test just rename the action attributes).
e.target.parentNode.removeChild(e.target);
// Or alternatively just hide the form: e.target.style.display = 'none';
history.replaceState({success:true}, 'title', "/success.html");

// This is working too!!! (uncomment the history.xxxState(..) line above before) (it ALSO works when the http response isn't a redirect but just a 200)
//var request = new XMLHttpRequest();
//request.open('POST', '/login', true);
//request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//request.send("redirectTo=/dynamic.html");
}else{
e.target.submit();
}
}, 1000);
}, 1);
}, false);
</script>
18 changes: 18 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
// Run via "node server.js"
// For https uncomment some lines below and run "sudo /opt/bin/node server.js"
// FYI: Firefox only save passwords when page is served over https

var express = require('express');
var bodyParser = require('body-parser');
// Uncomment for https:
//var https = require('https');
var http = require('http');
var fs = require('fs');

// Uncomment for https:
//var options = {
// key: fs.readFileSync('/etc/nginx/ssl/my.key.pem'),
// cert: fs.readFileSync('/etc/nginx/ssl/my.cert.pem')
//};

var app = express();

app.use(bodyParser.urlencoded());

app.post('/login', function(req, res){
res.redirect(req.body.redirectTo);
// or for the XMLHttpRequest test (uncomment the redirect in the line above):
//res.send('Hello World!');
});

app.use(express.static(__dirname));
app.listen(8080);
// Uncomment for https:
// https.createServer(options, app).listen(443);
console.log("started");

0 comments on commit c0d9503

Please sign in to comment.