检查AngularJS中的浏览器cookie

时间:2016-10-08 18:13:29

标签: angularjs cookies hapijs

我按hapi-auth-cookie设置了Cookie。我可以检查AngularJS是否存在cookie?

data.js

server.register(Cookie, function(err) {
  if(err) {
    console.error(err);
    throw err;
  }

  server.auth.strategy('session', 'cookie', {
    password: 'fuckthebritisharmytooralooralooraloo',
    isSecure: false,
    cookie: 'session',
    ttl: 24*60*60*1000
  });

   server.route({
    method: 'POST',
    path: '/login',
    config: {
      auth: {
        mode: 'try',
        strategy: 'session'
      },
      plugins: {
        'hapi-auth-cookie': {
          redirectTo: false
        }
      },
      handler: function(req, res) {

        if (req.auth.isAuthenticated) {
          console.info('Already!');
          req.cookieAuth.clear(); // Delete
          return res.redirect('/');
        }
        var username = req.payload.username;

        db.get('user_' + req.payload.username).then(function(data) {
          var user = data;
          var pass = data.password;
          if(!user) {
            return console.error('Can`t find user!');
          }

          var password = req.payload.password;
          return Bcrypt.compare(password, pass, function(err, isValid) {
            if(isValid) {

              req.server.log('Boom, okay!');

              req.cookieAuth.set(user);

              return res.redirect('/');
            }
            return res.redirect('/login');

          })
        })
        .catch((err) => {
          if (err) {
            console.error(err);
            throw err;
          }
        });
      }
    }
  });
});

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您使用Angularjs 1.4及以上

,则可以这样访问
transform: translate(-50%, -50%)