Permalink
Browse files

Added back in sessionData value setting/getting.

  • Loading branch information...
1 parent c99c060 commit 5d48faaf4fe3aa2a50c67c8ae3cd77884c4ad7e6 Micheil Smith committed Dec 7, 2009
Showing with 14 additions and 25 deletions.
  1. +5 −25 Sessions.js
  2. +9 −0 demo.js
View
@@ -59,28 +59,6 @@
var session = {
sid: _sid,
expires: Math.floor((+new Date) + this.lifetime*1000),
- /*getHeader: function(){
- var parts = ['SID=' + this.sid];
- if(manager.path){
- parts.push('path=' + manager.path);
- }
- if(manager.domain){
- parts.push('domain=' + manager.domain);
- }
- if(manager.persistent){
- function pad(n) {
- return n > 9 ? '' + n : '0' + n;
- }
-
- var d = new Date(this.expires);
- var wdy = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
- var mon = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
-
- parts.push('expires=' + wdy[d.getUTCDay()] + ', ' + pad(d.getUTCDate()) + '-' + mon[d.getUTCMonth()] + '-' + d.getUTCFullYear() + ' ' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + ' GMT');
- }
- return parts.join('; ');
- },*/
-
data: function(key, value){
if(value){
manager.setData(this.sid, key, value);
@@ -154,18 +132,20 @@
var session = this.get(sid);
session.expires = Math.floor((+new Date) + this.lifetime*1000);
if(key){
- return session._data[key];
+ return session._data[key] ? session._data[key] : null;
} else {
return session._data;
}
};
SessionManager.prototype.setData = function(sid, key, value){
- var session = this.get(sid);
+ sys.log(">>> Set Data: "+sid+"[\033[0;32m"+key+"\033[0;0m] = "+JSON.stringify(value));
+
+ var session = this._sessionStore[sid];
session._data[key] = value;
session.expires = Math.floor((+new Date) + this.lifetime*1000);
- this.emit("change", this.sid, this._data);
+ this.emit("change", sid, session._data);
return session._data[key];
};
View
@@ -23,9 +23,18 @@ SessionManager.addListener("destroy", function(sid){
http.createServer(function(req, resp) {
var session = SessionManager.lookupOrCreate(req, resp);
+ var history = session.data("history");
+ history = history ? history : [];
+
+ history.push(req.uri.path);
+
var ret = "<p> Hi there, here is your browsing history: </p><ul>";
+ for(var i=0;i<history.length; ++i){
+ ret += '<li><a href="'+history[i]+'">'+history[i]+'</a></li>';
+ }
ret += "</ul><p> Here are some other fascinating pages you can visit on our lovely site: </p><ul><li><a href=foo>foo</a><li><a href=bar>bar</a><li><a href=quux>quux</a></ul>";
+ session.data("history", history);
resp.sendHeader(200, {
'Content-Type': 'text/html'
// How awesome am I? no need to set-cookie here!

0 comments on commit 5d48faa

Please sign in to comment.