diff --git a/src/app/login/login.controller.js b/src/app/login/login.controller.js index 6ffcb6c..49ef027 100644 --- a/src/app/login/login.controller.js +++ b/src/app/login/login.controller.js @@ -2,8 +2,8 @@ angular.module('supportAdminApp') .controller('LoginController', [ - '$scope', '$rootScope', '$location', '$state', 'AuthService', 'TokenService', 'UserV3Service', - function ($scope, $rootScope, $location, $state, $authService, $tokenService, $userV3Service) { + '$scope', '$rootScope', '$location', '$state', 'AuthService', 'TokenService', 'UserService', + function ($scope, $rootScope, $location, $state, $authService, $tokenService, $userService) { $scope.loggingIn = false; @@ -21,7 +21,7 @@ angular.module('supportAdminApp') $scope.loggingIn = false; return; } - $userV3Service.loadUser().then(function(currentUser) { + $userService.findById(token.userId).then(function(currentUser) { console.log('Login Success'); $rootScope.currentUser = currentUser; $state.go('index.main') diff --git a/src/app/users/users.service.js b/src/app/users/users.service.js index 66ecabe..6f5eb0d 100644 --- a/src/app/users/users.service.js +++ b/src/app/users/users.service.js @@ -4,9 +4,48 @@ angular.module('supportAdminApp') .factory('UserService', ['$q','$http', 'API_URL', function ($q, $http, API_URL) { // local dev - //API_URL = 'http://local.topcoder-dev.com:8080'; return ({ + /** find user by ID */ + findById: function(userId) { + if(!userId) { + return $q.reject({error : 'userId must be specified.'}); + } + + var request = $http({ + method: 'GET', + url: API_URL + '/v3/users/' + userId, + headers: { + "Content-Type":"application/json" + } + }); + + return request.then( + function(response) { + console.log(response); + return response.data.result.content; + }, + function(error) { + console.log(error); + var err; + if(error && error.data && error.data.result) { + err = { + status: error.status, + error : error.data.result.content + }; + } + if(!err) { + err = { + status: error.status, + error : error.statusText + }; + } + return $q.reject(err); + } + ); + }, // findById() + + /** find users */ find: function(options) { var opts = options || {}; diff --git a/src/components/common/topnavbar.html b/src/components/common/topnavbar.html index bccdc3c..8504471 100755 --- a/src/components/common/topnavbar.html +++ b/src/components/common/topnavbar.html @@ -1,6 +1,6 @@