angular.js/src/Users.js

36 lines
770 B
JavaScript
Raw Normal View History

2010-01-12 01:32:33 +00:00
function Users(server, controlBar) {
2010-01-06 00:36:58 +00:00
this.server = server;
this.controlBar = controlBar;
};
2010-01-09 23:02:43 +00:00
Users.prototype = {
2010-01-12 01:32:33 +00:00
'fetchCurrentUser':function(callback) {
2010-01-06 00:36:58 +00:00
var self = this;
this.server.request("GET", "/account.json", {}, function(code, response){
2010-01-23 23:54:58 +00:00
self['current'] = response['user'];
2010-01-06 00:36:58 +00:00
callback(response.user);
});
},
2010-01-12 01:32:33 +00:00
'logout': function(callback) {
2010-01-06 00:36:58 +00:00
var self = this;
this.controlBar.logout(function(){
2010-01-23 23:54:58 +00:00
delete self['current'];
2010-01-09 23:02:43 +00:00
(callback||noop)();
2010-01-06 00:36:58 +00:00
});
},
2010-01-12 01:32:33 +00:00
'login': function(callback) {
2010-01-06 00:36:58 +00:00
var self = this;
this.controlBar.login(function(){
self.fetchCurrentUser(function(){
2010-01-09 23:02:43 +00:00
(callback||noop)();
2010-01-06 00:36:58 +00:00
});
});
},
2010-01-12 01:32:33 +00:00
'notAuthorized': function(){
2010-01-06 00:36:58 +00:00
this.controlBar.notAuthorized();
}
};