我不确定语法,但是闪光灯无法正确显示 ...
我使用 express-flash-2 ,还尝试了其他库...
router.post('/changepassword',ensureAuthenticated, function(req, res){
if(req.body.newpwd == req.body.newpwdb){
db.query(SqlString.format("Select password FROM Userdata.users WHERE id=?",[req.user.id]), function(error, result){
if(bcrypt.compareSync(req.body.pwd, result[0].password)){
db.query(SqlString.format("SELECT * FROM Userdata.insecpwd WHERE password=?",[req.body.newpwd]), function(er,re){
if (!re[0]){
db.query(SqlString.format("SELECT salt FROM Userdata.salts WHERE userid=?",[req.user.id]), function(e,r){
if (e) throw e;
var hash = bcrypt.hashSync(req.body.newpwd, r[0].salt);
var sql = 'UPDATE Userdata.users SET password=? WHERE id =?';
db.query(SqlString.format(sql,[hash,req.user.id]),function(err,re){
if (err) throw err;
});
});
req.flash('msg','PWD changed');
}else {
req.flash('error','New PWD not secure enough');
}
});
}else{
req.flash('error','Old PWD incorrect');
}
});
}else{
req.flash('error','PWDS do not match');
}
res.redirect("/users/settings");
});
代码是否错误,还是我使用 Flash错误方式?谢谢