|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | angular.module('topcoderX') // eslint-disable-line angular/no-services |
4 | | - .controller('NavController', ['$scope', '$log', '$state', '$cookies', '$http', '$rootScope', |
5 | | - function ($scope, $log, $state, $cookies, $http, $rootScope) { |
| 4 | + .controller('NavController', ['$scope', '$log', '$state', '$cookies', 'jwtHelper', '$rootScope', |
| 5 | + function ($scope, $log, $state, $cookies, jwtHelper, $rootScope) { |
6 | 6 | $scope.$state = $state; |
7 | 7 | $scope.menuList = false; |
8 | 8 | $scope.user = {}; |
9 | 9 | $scope.appConfig = $rootScope.appConfig; |
10 | 10 |
|
11 | 11 | const token = $cookies.get('tcjwt'); |
12 | | - const req = { |
13 | | - url: $rootScope.appConfig.TC_USER_PROFILE_URL, |
14 | | - method: 'Get', |
15 | | - headers: { |
16 | | - Authorization: 'Bearer ' + token, |
17 | | - }, |
18 | | - }; |
19 | | - $http(req).then(function (tcUser) { |
20 | | - $scope.user = tcUser.data; |
21 | | - if (tcUser.data.copilot) { |
22 | | - $log.info('Success - user is a copilot'); |
23 | | - } else { |
24 | | - $log.warn('Warning - User isn\'t a a copilot'); |
| 12 | + const decodedToken = jwtHelper.decodeToken(token); |
| 13 | + $scope.user = {}; |
| 14 | + $scope.user['copilot'] = false; |
| 15 | + Object.keys(decodedToken).findIndex(function (key) { |
| 16 | + if (key.includes('roles')) { |
| 17 | + if (decodedToken['roles'].indexOf('copilot') > -1) { |
| 18 | + $scope.user['copilot'] = true; |
| 19 | + $log.info('User is a copilot'); |
| 20 | + } else { |
| 21 | + $log.info('user is not a copilot'); |
| 22 | + } |
| 23 | + return true; |
25 | 24 | } |
| 25 | + return false; |
26 | 26 | }); |
27 | 27 |
|
28 | 28 | $scope.forceStateProjects = function () { |
|
0 commit comments