angular.module('coopEval').service('appService', appService);
function appService($http, $q) {
this.getUserType = function () {
return $http.get('services/UserService/getUserType');
};
this.getUserInfo = function () {
var deferred = $q.defer();
// get the user info embedded in HTML by server
if (window.CoopEval && window.CoopEval.currentUser) {
deferred.resolve(window.CoopEval.currentUser);
} else {
// if not found call the API
$http.get('api/users/me').then(function (response) {
window.CoopEval = _.merge({}, window.CoopEval, {
currentUser: response.data
});
deferred.resolve(response.data);
}, function (response) {
deferred.reject(response);
});
}
return deferred.promise;
};
this.shibAuth = function () {
return $http.get('api/ritauth/shibAuthenicate');
};
this.logOut = function () {
return $http.get('services/AuthenticationService/logout');
};
}
|