Io user / socket authentication

I am new to this, I am creating a game in which users must be logged in and can interact with each other or a subset of other registered users.

My initial thought is that after they log in, add their / their websocket client ID to the array of registered users and this is what I am manipulating to find out who is logged in or not.

Is this a normal way to do this?

Thank!

+3
source share
2 answers

Depends on your definition of "normal" .; -)

" ", , .

, Node 'express' library ( 'connect', 'underneath') req.session , , :

// user login via POST
//   assumes we're posting two values: username and password
//   as urlencoded data

app.post('/login',function(req,res){

  var username=req.body['username']||'',
      password=req.body['password']||'';

  // check post data (username,password) 
  // against list of allowed users

  if(isAuthorized(username,password)) { // you provide isAuthorized()
    req.session.authorized=true;
  }
  else {
    // display an error message to user
    // and redirect back to the login form
  }
});

// user logout via GET
app.get('/logout',function(req.res){
  req.session.destroy();
});

, , , req.session.authorized , , .

. http://expressjs.com/guide.html

+4

: http://www.danielbaulig.de/socket-ioexpress/

, , node.js. redisStore (, 3 :))

+1

All Articles