I'm trying to create a server with an ability to "logon" (the Username and Password must match). I'm trying to do this in "low-level" so to speak, no extensions or anything. Right now when the pages are pulled up they are all accessible and the form displays but when the button is click nothing happens. Nothing is written to the console and check() is never called.
I've tried a lot of things - changing the function, the type of button, the way I'm getting the data from the form and none of it seems to be working. I would really appreciate a push in the right direction (and, total side note, if someone could also talk a moment about how to set a cookie when the user is logged on I would appreciate it as well, but this is very much extra to the question at hand).
var http = require("http");
var url = require("url");
var server = http.createServer(function (req, response){
var page = url.parse(req.url).pathname;
response.writeHead(200, {'Content-Type':'text/html'});
if (page == '/'){
//home page
}
else if (page == '/page1'){
//page one
}
else if (page == '/auth'){
response.write('<html>'+
'<h1><center>Sign up for dumblr home of the dumblr</center></h1>'+
'<form method="POST" name="auth" >'+
'Username: <input type="text" name="user" required /> <br />'+
'Password: <input type="password" name="pwd" required/> <br /> '+
'<input type="button" value="Submit" onclick="check(this.form)"/> '+
'</form>');
function check(form){
console.log("1");
if(form.user.value == form.pwd.value){
//response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
console.log("Cookie is set");
return true;
}
else{
response.write("<h1>Sorry, those are not correct. Try again.</h1>")
console.log("Didn't work")
return false;
}
}
}
response.end();
}).listen(3000);
console.log('Server running at http://127.0.0.1:3000');