router.post('/loginv', function (req,res) {
var id = req.body.id;
var pass = req.body.pass;
if(login.login(id,pass)=='validated'){
res.sendfile('views/welcome.html');
}else{
res.send('dont give up');
}
var result = login.login(id,pass);
console.log(result);
});
module.exports={
login : function(id,pass){
var q = "SELECT * FROM user where id = ? and pass = ?";
var ret = 'default';
DB.DB.query(q, [id,pass], function (error,result) {
if(error){
console.log('not found');
ret = 'unrecognized';
} else{
console.log('found');
ret = 'validated';
}
});
return ret;
}};
console.log :
GET /login 304 4.028 ms - -
default
POST /loginv 200 40.558 ms - 12
found
found
as you can see the value ret returned from the following code is not being changed although it follows the procedure of the function properly.. i'm new to node js and js stuff so any comments and advice will definitely be helpful thx :)