Created
June 5, 2013 07:17
-
-
Save akshar100/5712149 to your computer and use it in GitHub Desktop.
Mojito Session Management Addon. Note: This addon is not tested. It is vulnerable to session hijacking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI.add('mojito-session-addon', function(Y, NAME) { | |
function MojitoSession(command, adapter, ac) { | |
// The "command" is the Mojito internal details | |
// for the dispatch of the mojit instance. | |
// The "adapter" is the output adapter, containing | |
// the "done()", "error()", etc, methods. | |
// The "ac" is the ActionContext object to which | |
// this addon is about to be attached. | |
var sessionCookie = ac.cookie.get("sid"); | |
if(!sessionCookie){ | |
ac.cookie.set("sid", ""+Math.random()+":"+Math.random()); | |
sessionCookie = ac.cookie.get("sid"); | |
} | |
if(!Y.MemoryStore){ | |
Y.MemoryStore = { | |
}; | |
Y.MemoryStore[sessionCookie] = {}; | |
}else{ | |
if(!Y.MemoryStore[sessionCookie]){ | |
Y.MemoryStore[sessionCookie] = {}; | |
} | |
} | |
this.sessionCookie = sessionCookie; | |
} | |
MojitoSession.prototype = { | |
// The "namespace" is where in the ActionContext | |
// the user can find this addon. The namespace | |
// must be the same as the first part of the addon file. | |
// Thus, this addon file must be named 'cheese'.{affinity}.js' | |
namespace: 'session', | |
set: function(name,value) { | |
Y.MemoryStore[this.sessionCookie][name] = value; | |
}, | |
get: function(name){ | |
return Y.MemoryStore[this.sessionCookie][name]; | |
} | |
}; | |
// If this addon depends on another, that can | |
// be specified here. Circular dependencies are not | |
// supported or automatically detected, | |
// so please be careful. | |
MojitoSession.dependsOn = ['http']; | |
Y.mojito.addons.ac.session = MojitoSession; | |
}, '0.0.1', {requires: ['mojito','mojito-cookie-addon']}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment