aboutsummaryrefslogtreecommitdiffstats
path: root/src/Users.js
blob: c0c15848523ba5aebbb7cea77d0c3889b9b87a66 (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
36
// Copyright (C) 2008,2009 BRAT Tech LLC
nglr.Users = function(server, controlBar) {
  this.server = server;
  this.controlBar = controlBar;
};

nglr.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||nglr.noop)();
    });
  },
  
  login: function(callback) {
    var self = this;
    this.controlBar.login(function(){
      self.fetchCurrentUser(function(){
        (callback||nglr.noop)();
      });
    });
  },

  notAuthorized: function(){
    this.controlBar.notAuthorized();
  }
};