I am currently "developing" a small Log In Page, and i want to set the "H2" to "Password Incorrect" or something similar, when the User input is invalid.
This is my HTML:
<!DOCTYPE html>
<html>
<head>
<script>
<script src="jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="http://localhost/style2.css">
<script src="server.js"></script>
</head>
<body id="body">
<div id="div">
<h1 id="h1">Log In</h1>
</div>
<form action="" method="post" enctype="multipart/form-data">
<div id="rahmen">
<label class="label" for="name">Benutzer:</label>
<br>
<input class="input" id="name" name="name"/>
<br>
<label class="label" for="passwort">Passwort:</label>
<br>
<input class="input" id="passwort" name="passwort"/>
<br>
<input id="button" type="submit" value="Log In"/>
<br>
<h2 id="h2"></h2>
</div>
</form>
</body>
</html>
My Server.js compares the Input of the User with Values in the DynamoDB (AWS)
(I omitted the Initialization and DynamoDB Code Parts)
Server.js :
var server = http.createServer(function (req, res) {
if (req.method.toLowerCase() == 'get') {
displayForm(res);
} else if (req.method.toLowerCase() == 'post') {
processAllFieldsOfTheForm(req, res);
}
});
function displayForm(res) {
fs.readFile('test.html', function (err, data) {
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': data.length
});
res.write(data);
res.end();
});
}
docClient.query(Params, function(err, data) {
switch(true) {
case(data.Count == 0 || fields.passwort != data.Items[0].Passwort):
// change h2 to "Username or Password Incorrect" here.....
break;
case(fields.passwort == data.Items[0].Passwort):
fs.createReadStream('index.html').pipe(res);
break;
}
});
I don't know how to handle that with Ajax/Bodyparser, i tried many examples, and everytime it's just loading and loading.
BTW: If User input is valid, the redirection to the "index.html" works just fine. I just can't get the Error Message to run.
Can anyone help me out? Code examples highly appriciated!