最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用不响应节点的护照认证

运维笔记admin11浏览0评论

使用不响应节点的护照认证

使用不响应节点的护照认证

我正在尝试通过nodejs和mongodb使用护照认证,下面是代码,我已经尝试过了,没有得到任何回应。它甚至没有输入findOrCreate方法。

我正在使用nodejs v: 10.16.3npm v: 6.9.0

[mongodb version:4.2.0,操作系统是MAC OS Mojave

这里是依赖项列表-

"dependencies": {
    "body-parser": "^1.19.0",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.4",
    "express": "^4.17.1",
    "express-session": "^1.16.2",
    "flash": "^1.1.0",
    "http": "0.0.0",
    "mongo": "^0.1.0",
    "mongodb": "^3.3.2",
    "mongoose": "^4.3.5",
    "mysql": "^2.17.1",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0"
  }

护照代码如下-

 app.post("/signup",(req,res)=>{
    console.log("Inside Signup",req.body);
    res.send(req.body);
    var emails=req.body.Email;
    console.log(emails);
    var names=req.body.Name;
    console.log(names);
    var passwords=req.body.Password;
   console.log(passwords);
    si(names,emails,passwords);
  });
 function si(username,email,password){
      passport.use('signup', new LocalStrategy({
        passReqToCallback : true
      },
      function(req, username, password, done) {
        findOrCreateUser = function(){
          // find a user in Mongo with provided username
    console.log("Step1 success");
          console.log(username);
          console.log(email);
          console.log(password);
          var dbo = db.db("record");
          dbo.collection("records").findOne({'Username':username}, function(err, result) {
            if (err){
              console.log('Error in SignUp: '+err);
              return done(err);
            }
            // already exists
            if (result) {
              console.log('User already exists');
              return done(null, false, 
                 req.flash('message','User Already Exists'));
            } else {
              var newUser = new User();
              newUser.Username = username;
              newUser.Password = password;
              newUser.Email = email;
              newUser.save(function(err) {
                if (err){
                  console.log('Error in Saving user: '+err);  
                  throw err;  
                }
                console.log('User Registration succesful');    
                return done(null, newUser);
              });
            }
          });
        };

        // Delay the execution of findOrCreateUser and execute 
        // the method in the next tick of the event loop
        process.nextTick(findOrCreateUser);
      }))
};

任何人都可以提出建议,我该如何运作?

回答如下:

[尝试通过将对象传递给构造函数来创建用户,而不是分别更改属性。

newUser = new User({ username: username, email: emal, password: password });

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论