首页 文章

phonegap使用nodejs-expresss-mongo-passportjs进行ajax用户身份验证

提问于
浏览
3

我已经构建了一个基于node.js,express.js,passport-local的基本node.js用户认证系统 .

我将用户名和密码存储在mysql数据库中,并使用mongo进行会话的持久存储 . 我现在想要移动用户注册并登录phonegap .

从我在网上找到的教程中,似乎工作的唯一方法是AJAX用户身份验证 . 但是我有两个问题:

  • 如何重写快速路由以响应JSON,因为passport.js依赖于重定向?
// process the signup form
app.post('/register', passport.authenticate('local-signup', {
        successRedirect : '/home', 
        failureRedirect : '/register', 
        failureFlash : true // allow flash messages
    })); 

 // process the login form
app.post('/login', passport.authenticate('local', {
    successRedirect : '/home', 
    failureRedirect : '/login', 
    failureFlash : true // allow flash messages
}));
 

 and in my strategies I have : 
passport.use('local-signup', new LocalStrategy({
        usernameField : 'email',
        passwordField : 'password',
        passReqToCallback : true 
    },
    function(req, email, password, done) {
...
rest of the code that queries the db 

 also for login 
//Configure passport Local Strategy for login
passport.use(new LocalStrategy(
  function(username, password, done) {
  var query = 'select * from users where email = '+  connection.escape(username);
    connection.query(query, function (err, user) {
      if (err) { return done(err); 
... rest of code
}

2.通过发送邮件到'/login'并因此在快速服务器中创建新的活动会话,PhoneGap中的AJAX身份验证是否有效?

3.我如何处理客户的状态 . 在正常的Web应用程序中,您使用重定向即ie . 失败的登录尝试,注销等 . 在AJAX身份验证中,您如何处理?您是否返回状态代码,返回新标记,更新视图的一部分?

1 回答

  • 3

    我会在做一些研究时关闭这个问题,而我最初的问题是由于我对如何构建phonegap应用程序缺乏了解 . 我不知道我需要遵循单页面应用程序架构与传统网页模型 .

相关问题