(优发娱乐官网) passport的LocalStrategy一直没起作用

我在以下代码第二行添加了输出信息,但是发现程序没有进来,求解答
环境:windows 10
包的版本

数据库读取正常,router.post可以获取到req.body的值,没有问题,同时也获得到err user info
值分别为

err: null
user: false
info: { message: Missing credentials }

贴上相关代码
app.js

var session = requireexpress-session;
var bcrypt = requirebcrypt-nodejs;
var path = requirepath;
var favicon = requireserve-favicon; var logger = requiremorgan;
//登陆模块涉及包
var passport = requirepassport;
var LocalStrategy = requirepassport-local.Strategy; var routes = require./routes/index;
var users = require./routes/users; var model = require./database/model; var app = express; //登陆模块
passport.usenew LocalStrategyfunctionuserEmail, userPassword, done{ console.loguserEmail, userPassword; new model.User{userEmail: userEmail}.fetch.thenfunctiondata{ var user = data; console.logdata; ifuser === null{ return donenull, false, {message: 此账号不存在}; } else { user = data.toJSON; if!bcrypt.compareSyncuserEmail, user.userPassword { return donenull, false, {message: 账号密码错误}; } else { return donenull, user; } } };
}; passport.serializeUserfunctionuser, done{ donenull, user.userEmail;
}; passport.deserializeUserfunctionusername, done { new model.User{userEmail: user.userEmail}.fetch.thenfunctionuser { donenull, user; };
}; app.useloggerdev;
app.usebodyParser.json;
app.usebodyParser.urlencoded{ extended: false };
app.usecookieParser;
app.usesession{secret: keyboard};
app.useexpress.staticpath.join__dirname, public;

路由部分index.js

var express = requireexpress;
var router = express.Router;
var passport = requirepassport;
var bcrypt = requirebcrypt-nodejs; var model = require../database/model; router.post/login, functionreq, res, next{ console.logreq.body; passport.authenticatelocal, { successRedirect: /, failureRedirect: /login }, functionerr, user, info{ console.logerr, user, info; iferr { return res.renderlogin, {title: 登录, errorMessage: err.message}; } if!user { return res.renderlogin, {title: 登陆, errorMessage: info.message}; } return req.logInuser, functionerr{ iferr { return res.renderlogin, {title: 登陆, errorMessage: err.message}; } else { return res.redirect/project; } }; }req, res, next;
};

package.json

{ "name": "app9d", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "express": "4.x", "body-parser": "*", "bookshelf": "0.5", "cookie-parser": "*", "debug": "~2.2.0", "jade": "~1.11.0", "morgan": "~1.6.1", "serve-favicon": "~2.3.0", "passport": "*", "passport-local": "*", "bcrypt-nodejs": "*", "express-session": "*", "mysql": "*" }
}

已经知道原因了,因为我使用的email注册,所以要设置usernameField

发表评论

电子邮件地址不会被公开。 必填项已用*标注