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

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();
  }
};