【发布时间】:2016-09-03 21:29:42
【问题描述】:
我正在编写 angular + node js 应用程序,并且我有一个使用 http post 调用验证用户和密码的登录方法:
login.js
$scope.userLogin = function (info) {
$http.post('/authenticate_user', {'name':info.name,'password':info.password})
.success(function(data) {
})
.error(function(data) {
console.log('Error:'+ data);
});
}
在 server.js 文件上我正在处理身份验证:
app.post('/authenticate_user', function(req, res){
authenticate_user(req, res);
});
var authenticate_user=function(req, res){
var query= user_details.find({'name': req.body.name});
res.setHeader("Cache-Control", "private, no-cache, no-store, must-revalidate, max-age=0");
query.exec( function(err, docs){
if (docs.length==0) return false;
res.json(docs[0].password==req.body.password);
});
}
我希望我的 login.js 文件中的 userLogin 函数具有 app.post() 方法的值..
类似
$http.post('/authenticate_user', {'name':info.name,'password':info.password})
.success(function(data) {
// what is data includes here? the response for the http post?
// or what the function I calling to aka authenticate_user, returns - in this case - a boolean value?
})
我希望将我的 api 帖子中的值传输到 login.js 文件中的调用方法..
你知道怎么做吗?
谢谢
【问题讨论】:
标签: javascript angularjs node.js http