我在检查 Redis 中的用户名和密码时遇到问题,它说用户名和密码未定义。我希望你能帮助我解决 NodeJs/ExpressJs 中的这个问题。
代码:
应用程序.js
var express = require('express');
var app = express();
var redis = require("redis"),
client = redis.createClient();
var user, pass;
app.use(express.bodyParser());
client.on("error", function (err) {
console.log("error event - " + client.host + ":" + client.port + " - " + err);
});
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.post('/', function (req, res) {
console.log("");
console.log("--------------------");
console.log(req.body.user.username);
console.log(req.body.user.password);
console.log("--------EOF---------");
client.hmget(req.body.user.username + user, req.body.user.pasword + pass,
redis.print);
if (req.body.user.username && req.body.user.password == user && pass)
{
res.write("Successfully logged in!");
}
else
{
res.write("Username or Password is incorrect");
}
console.log("req.body.username: " + req.body.username);
console.log("req.body.password: " + req.body.password);
console.log("username: " + user);
console.log("username: " + pass);
res.end();
});
app.listen(80)
这是我的 index.html 代码。
索引.html
<html>
<head></head>
<body>
<form method="post" action="/">
Username: <input type="text" name="user[username]" > <br>
Password: <input type="text" name="user[password]"> <br>
<input type="submit" value="Submit">
</form>
</body>
</html>