我无法使用PassportJS将名称插入表格

时间:2018-07-10 22:26:36

标签: node.js express passport.js

我正在为我的任务开发身份验证系统,下表如下:

CREATE TABLE `' + dbconfig.database + '`.`' + dbconfig.users_table + '` ( \
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, \
  `name` VARCHAR(100) NOT NULL, \
`username` VARCHAR(20) NOT NULL, \
`password` CHAR(60) NOT NULL, \
    PRIMARY KEY (`id`), \
UNIQUE INDEX `id_UNIQUE` (`id` ASC), \
UNIQUE INDEX `username_UNIQUE` (`username` ASC) \
)');

在注册页面上,我具有名称,用户名和密码,在护照上的注册部分上,我具有以下代码:

  passport.use(
        'local-signup',
        new LocalStrategy({
            // by default, local strategy uses username and password, we will override with email
          //  nameField: 'name',
            usernameField : 'username',
            passwordField : 'password',
            passReqToCallback : true // allows us to pass back the entire request to the callback
        },
        function(req, username, password, done) {
            // 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
            connection.query("SELECT * FROM users WHERE username = ?",[username], function(err, rows) {
                if (err)
                    return done(err);
                if (rows.length) {
                    return done(null, false, req.flash('signupMessage', 'That username is already taken.'));
                } else {
                    // if there is no user with that username
                    // create the user
                    var newUserMysql = {
                        username: username,
                        password: bcrypt.hashSync(password, null, null)  // use the generateHash function in our user model
                    };

                    var insertQuery = "INSERT INTO users (username, password ) values (?, ?)";

                    connection.query(insertQuery,[newUserMysql.username, newUserMysql.password],function(err, rows) {
                        newUserMysql.id = rows.insertId;

                        return done(null, newUserMysql);
                    });
                }
            });
        })
    );

我尝试了很多尝试在注册时插入名称的方法,但是当它起作用时,密码进入了用户名字段,而用户名进入了数据库上的名称字段。

我想护照不是我将名字插入桌子的地方。

无论如何,希望我能得到一些帮助,在用户表上插入姓名,谢谢!

0 个答案:

没有答案