woodpecker/server/app/scripts/services/auth.js
Brad Rydzewski 83577a7d5d removed css files. designers will be providing
removed amber files. replacing with angular
removed queue package in favor or worker package
removed channel package in favor of pubsub package
2014-06-21 14:22:38 -07:00

34 lines
No EOL
828 B
JavaScript

'use strict;'
angular.module('app').service('authService', function($q, $http) {
return{
user : null,
// getUser will retrieve the currently authenticated
// user from the session. If no user is found a 401
// Not Authorized status will be returned.
getUser : function() {
var _this = this;
var defer = $q.defer();
// if the user is already authenticated
if (_this.user != null) {
defer.resolve(_this.user);
}
// else we need to fetch from the server
$http({method: 'GET', url: '/v1/user'}).
success(function(data) {
_this.user=data;
defer.resolve(_this.user);
}).
error(function(data, status) {
_this.user=null;
defer.resolve();
});
// returns a promise that this will complete
// at some future time.
return defer.promise;
}
}
});