angular.js/src/Users.js

37 lines
796 B
JavaScript
Raw Normal View History

2010-01-06 00:36:58 +00:00
// Copyright (C) 2008,2009 BRAT Tech LLC
2010-01-09 23:02:43 +00:00
Users = function(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-06 00:36:58 +00:00
fetchCurrentUser:function(callback) {
var self = this;
this.server.request("GET", "/account.json", {}, function(code, response){
self.current = response.user;
callback(response.user);
});
},
logout: function(callback) {
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
});
},
login: function(callback) {
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
});
});
},
notAuthorized: function(){
this.controlBar.notAuthorized();
}
};