Created
June 28, 2012 20:57
-
-
Save gsdevme/3013851 to your computer and use it in GitHub Desktop.
Session class, singleton
This file contains 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
/*jslint nomen: true */ | |
/*global console, define, Backbone, $, _ */ | |
define([ | |
'backbone' | |
], function () { | |
'use strict'; | |
var _session = null, _instantiated = false; | |
function init() { | |
return _.extend({ | |
authenticate: function () { | |
}, | |
get: function (val) { | |
return _session[val] || null; | |
}, | |
getSession: function () { | |
return _session; | |
}, | |
isAllowed: function () { | |
return true; | |
}, | |
isLoggedIn: function () { | |
return true; | |
} | |
}, Backbone.Events); | |
} | |
// Public methods | |
return { | |
getInstance: function () { | |
if (_instantiated === false) { | |
_session = ({ | |
_id: 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3', | |
uid: 11, | |
username: 'Bob', | |
packages: [ | |
{ | |
_ref: 'de9f2c7fd25e1b37588hha0bd17d9b100db4b3', | |
packageName: 'Small-256', | |
masterDomain: 'google.com', | |
subDomains: ['price.google.com', 'foo.google.com'], | |
expires: 133566111 | |
} | |
], | |
permissions: [ | |
] | |
}); | |
console.log('Session Created'); | |
_instantiated = init(); | |
} | |
return _instantiated; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment