好吧,我放棄了。Redis和NodeJs - 無法驗證用戶
我試過很多事情來創建一個簡單的登錄表單。該表單本身呈現罰款,它只是處理POST數據是錯誤的:-)
我有一個Redis數據庫中有一些鍵。首先,有一個users
設置用戶列表(目前,只有用戶:管理員)。其次,只有一個密碼hkey user:admin
。看到下面的屏幕。
用下面的代碼,當我提交表單,它不會在Redis的回調函數得到來電:
var username = req.body.username;
var password = req.body.password;
// Now, check if the user he entered exists
client.sismember(['users', 'user:' + username], function(err, reply) {
// IT NEVER GETS THERE
if (reply) {
// If he does, check if the password matches
client.hget(['user:' + username, 'password'], function(err, reply) {
if (reply === password) {
// If the password matches, add the session and redirects to home
req.session.username = username;
res.redirect('/home');
}
else {
options.error = "Password do not match.";
res.render('guest', options);
}
});
}
else {
options.error = "Username does not exist.";
res.render('guest', options);
}
});
我使用的console.log來檢查一些東西,並且username
和password
填寫得很好。
關於redis服務器連接(如果關閉服務器,我有這個問題)沒有錯誤,所以問題不存在。
我試過使用client.send_command()來代替,但沒有改變。
任何幫助將不勝感激!
我正在爲您投票。這是我能爲你做的最多事情:-) –