Passport身份验证和JSON响应

时间:2013-08-20 12:24:26

标签: json node.js web-applications passport.js

我正在NodeJS中构建一个Web应用程序。

应用程序中的后端仅通过Json API与用户连接。我正在尝试登录选项。这是可能的?我怎样才能收到Passport Authenticate的回复?

  

function post_api(req,res){

res.writeHead(200, { 'Content-Type': 'application/json' });    
// Check method
if(!req.body.method)
  res.write( JSON.stringify({
          "status":"400",
          "response": {
            "status" : "error",
            "info":  "Method not defined."
          } 
      }));
else
{

    if(req.body.method == "login")
    { 

        passport.authenticate('local', {failureFlash: true, successFlash: true});  
        // Something here but i have no idea what...

        res.write( JSON.stringify({
            "status":"200",
            "response": {
                "status" : "error", // or success
                "info":  req.flash('error')
            }
        })); 

    }
    else
      res.write( JSON.stringify({
          "status":"404",
          "response": {
            "status" : "error",
            "info":  "Method not found."
          } 
      }));

}    
res.end(); };

这当然不起作用,应该怎么样?

0 个答案:

没有答案
相关问题