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){
|
|
|
|
|
self.current = response.user;
|
|
|
|
|
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(){
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
};
|