【发布时间】:2018-01-14 23:22:16
【问题描述】:
您好,我正在学习 express 和护照,我尝试做一个注册表单,当我尝试使用 MySQL 插入一行时,我收到了这个错误,但我的表正在正确更新。
passport.use(
'local-signup',
new LocalStrategy({
usernameField : 'email',
passwordField : 'password',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, first_name, done) {
var displayName = req.body.first_name;
// find a user whose email is the same as the forms email
// we are checking to see if the user trying to login already exists
dbConnection.query("SELECT * FROM users WHERE email = ?",[email], function(err, rows) {
if (err) {
return done(err);
}
if (rows.length) {
return done(null, false, { error: 'That email is already being used.' });
} else {
// if there is no user with that email
// create the user
var salt = bcrypt.genSaltSync(10);
var passwordHash = bcrypt.hashSync(password, salt);
var userInfo = {
email: email,
first_name: displayName
};
var insertQuery = "INSERT INTO users ( email, password, first_name) values ('"+email+"','"+passwordHash+"','"+displayName+"')";
console.log(insertQuery);
dbConnection.query(insertQuery,function(err, rows) {
userInfo.id = rows.insertId;
console.log(rows);
return done(null, userInfo);
});
}
});
})
);
【问题讨论】:
标签: mysql express passport.js