Created
December 30, 2011 23:49
-
-
Save zackham/1542095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get currently logged in user | |
* @method getCurrent | |
* @static | |
* @return {Promise} A promise for the currently authenticated user | |
*/ | |
User.getCurrent = function() { | |
if(this.currentDfd) | |
return this.currentDfd; | |
var dfd = this.currentDfd = new $.Deferred(); | |
// we might already have a user prepopulated, let's check | |
if(rwgps.ns('config').currentUser !== undefined) { | |
if(rwgps.config.currentUser) { | |
dfd.resolve(new User(rwgps.config.currentUser)); // we have a user | |
} else { | |
dfd.reject(); // user is not logged in | |
} | |
} else { | |
$.getJSON(baseURL + '/users/current.js?callback=?', function(data) { | |
if(data) { | |
dfd.resolve(new User(data)); | |
} else { | |
dfd.reject(); | |
} | |
}); | |
} | |
return dfd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment