mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
35 lines
779 B
JavaScript
35 lines
779 B
JavaScript
function Users(server, controlBar) {
|
|
this.server = server;
|
|
this.controlBar = controlBar;
|
|
};
|
|
|
|
extend(Users.prototype, {
|
|
'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'];
|
|
(callback||noop)();
|
|
});
|
|
},
|
|
|
|
'login': function(callback) {
|
|
var self = this;
|
|
this.controlBar.login(function(){
|
|
self['fetchCurrentUser'](function(){
|
|
(callback||noop)();
|
|
});
|
|
});
|
|
},
|
|
|
|
'notAuthorized': function(){
|
|
this.controlBar.notAuthorized();
|
|
}
|
|
});
|