all files / js/ app.service.js

11.76% Statements 2/17
0% Branches 0/4
0% Functions 0/7
11.76% Lines 2/17
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 37 38                                                                        
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');
  };
}