aboutsummaryrefslogtreecommitdiffstats
path: root/src/moveToAngularCom/Users.js
blob: fb5845d320f2c2fa6c6915f1a2de24a302fd0ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();
  }
});