My Server is Windows 2008R2.

I ran node.js and setup Redis on my server to run with the default setting

Here is my code:

var  express = require('express');
var RedisStore = require('connect-redis')(express);

var sessionStore = new RedisStore({
host: 'localhost',
port: "6379",
db: 'sessionsdb'
});


app.configure(function () {
 
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({ store: sessionStore ,  secret: secretkey}));
});

app.post('/Login', function (req, res){
   
  var post = req.body;   
  var _Email = post.email;
  var _password = post.password; 
 
 

 console.log ('Password: ' + _password);
 console.log ('ID: ' + _Email);
 
    
    try 
    {
        clientsql.query('SELECT * FROM tbmembership WHERE email="' + _Email 
+ '" AND MobilePassword="' + _password + '"',
        function (err, results, fields) 
        {
            if (!err)
            {
                if (results[0])
                { 
                    try
                    {
                        req.session.regenerate(function()
                        {                                
                            req.session.userid = results[0].userId;
                            req.session.is_logged_in = true;
                        });
                        console.log ('Login is good in the try catch- ' + 
req.session.userid + ' Status = ' + req.session.is_logged_in );
                    }
                    catch (err)
                    {
                        console.log('Set session is bad' + err);
                    }
                    
                    //req.session.save();
                    
                    console.log ('Login is good - ' + req.session.userid + 
' Status = ' + req.session.is_logged_in );
                    res.send("" + results[0].userId + "");
                }
            }                        
        });
    }
    catch (err)
    {
        console.log("Error - Logout Error - status = " + err);
        res.send("" + 0 + "");
    }     
});

The problem I have is that after login, it cannot get the value in the 
session. req.session.userid is undefined and req.session.is_logged_in is 
undefined .

I have two scripts running one is for retrieve the data running on a 
different IP and port, and one to handle login and logout.

What did I do wrong in here so that the session values are all undefined 
even right after I set it?

Thanks you

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to