node.js - Nodejs login information saving problem
天蓬老师
天蓬老师 2017-05-16 13:32:05
0
1
376

After I log in on one computer, the logged-in user information will be shared on another computer that is not logged in. However, I just store it in a cookie. Logically speaking, the two clients are not mutually exclusive. Don't you want to interfere? Please give me some guidance from God

Login login.js

router.post('/login',function(req, res, next){
    var account=req.body.account;  //账号
    var password=req.body.password; //密码
    var options = {
        method:'post',
        uri:"/login",
        qs:{account:account,password:password},
        headers:{'User-Agent': 'Request-Promise'},
        json: true
    }
    
    http.tp(options,function(error, response, body){
        res.cookie('_user', body.data, {maxAge: 24*60*60 * 1000});  //登录成功后把后台返回的信息保存到cookie
        res.redirect('back');
    })
})

app.js

app.use(function(req, res, next){
  var _user=req.cookies._user;   //获取保存到cookie的用户信息

  res.locals.user =_user;    //发送给浏览器
  res.locals._user =_user;
  res.locals.success = req.flash('success').toString();
  res.locals.error = req.flash('error').toString();
  next();
});

When I save information in this way, won’t the cookie be saved only on the client browser where I log in?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
世界只因有你

The cookie is saved to the server?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!