diff options
Diffstat (limited to 'pyload/web/app/scripts/models/UserSession.js')
-rw-r--r-- | pyload/web/app/scripts/models/UserSession.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/pyload/web/app/scripts/models/UserSession.js b/pyload/web/app/scripts/models/UserSession.js new file mode 100644 index 000000000..7bf6abd8f --- /dev/null +++ b/pyload/web/app/scripts/models/UserSession.js @@ -0,0 +1,38 @@ +define(['jquery', 'backbone', 'underscore', 'utils/apitypes', 'app'], + function($, Backbone, _, Api, App) { + 'use strict'; + + // Used in app -> can not have a dependency on app + return Backbone.Model.extend({ + + idAttribute: 'name', + + defaults: { + uid: -1, + name: 'User', + permissions: null, + session: null + }, + + // Model Constructor + initialize: function() { + this.set(JSON.parse(localStorage.getItem('user'))); + }, + + save: function() { + localStorage.setItem('user', JSON.stringify(this.toJSON())); + }, + + destroy: function() { + localStorage.removeItem('user'); + }, + + // TODO + fetch: function(options) { + options = App.apiRequest('todo', null, options); + + return Backbone.Model.prototype.fetch.call(this, options); + } + + }); + });
\ No newline at end of file |