Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To work cookie-session #937

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
95 changes: 62 additions & 33 deletions lib/sessionmanager.js
Expand Up @@ -25,33 +25,52 @@ SessionManager.prototype.logIn = function(req, user, options, cb) {

// regenerate the session, which is good practice to help
// guard against forms of session fixation
req.session.regenerate(function(err) {
if (err) {
return cb(err);
}

if (req.sessionID) {
req.session.regenerate(function(err) {
if (err) {
return cb(err);
};

self._serializeUser(user, req, function(err, obj) {
if (err) {
return cb(err);
}
if (options.keepSessionInfo) {
merge(req.session, prevSession);
}
if (!req.session[self._key]) {
req.session[self._key] = {};
}
// store user information in session, typically a user id
req.session[self._key].user = obj;
// save the session before redirection to ensure page
// load does not happen before session is saved
req.session.save(function(err) {
if (err) {
return cb(err);
}
cb();
});
});
});
} else {
// To work cookie-session
self._serializeUser(user, req, function(err, obj) {
if (err) {
return cb(err);
}
req.session = {}

if (options.keepSessionInfo) {
merge(req.session, prevSession);
}
};
if (!req.session[self._key]) {
req.session[self._key] = {};
}
// store user information in session, typically a user id
};
req.session[self._key].user = obj;
// save the session before redirection to ensure page
// load does not happen before session is saved
req.session.save(function(err) {
if (err) {
return cb(err);
}
cb();
});
cb();
});
});
}
}

SessionManager.prototype.logOut = function(req, options, cb) {
Expand All @@ -68,28 +87,38 @@ SessionManager.prototype.logOut = function(req, options, cb) {
// clear the user from the session object and save.
// this will ensure that re-using the old session id
// does not have a logged in user
if (req.session[this._key]) {
delete req.session[this._key].user;
if (req.session[self._key]) {
delete req.session[self._key].user;
}
var prevSession = req.session;

req.session.save(function(err) {
if (err) {
return cb(err)
}

// regenerate the session, which is good practice to help
// guard against forms of session fixation
req.session.regenerate(function(err) {
if (req.sessionID) {
req.session.save(function(err) {
if (err) {
return cb(err);
}
if (options.keepSessionInfo) {
merge(req.session, prevSession);
}
cb();
};

// regenerate the session, which is good practice to help
// guard against forms of session fixation
req.session.regenerate(function(err) {
if (err) {
return cb(err);
}
if (options.keepSessionInfo) {
merge(req.session, prevSession);
}
cb();
});
});
});
} else {
// to work cookie-session
req.session = null;
if (options.keepSessionInfo) {
req.session = {}
merge(req.session, prevSession);
}
cb();
}
}


Expand Down