aboutsummaryrefslogtreecommitdiffstats
path: root/src/Users.js
blob: f81507f45048490941ed8aef83c385ec72778724 (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();
  }
});