1(function () { 2 'use strict'; 3 4 angular 5 .module('app') 6 .factory('authService', authService); 7 8 authService.$inject = ['$http', '$q', 'localStorageService']; 9 10 function authService($http, $q, localStorageService) { 11 12 var authServiceFactory = {}; 13 14 var _authentication = { 15 isAuth: false, 16 userName: '' 17 }; 18 19 var _login = function (loginData) { 20 21 var data = "grant_type=password&username=" + loginData.userName + "&password=" + loginData.password + "&productConfirmationCode=" + loginData.productConfirmationCode; 22 23 var deferred = $q.defer(); 24 25 $http.post('/token', data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).then(function (response) { 26 27 localStorageService.set('authorizationData', { token: response.data.access_token, userName: loginData.userName, fullName: response.data.FullName, roles: JSON.parse(response.data.Roles) }); 28 29 _authentication.isAuth = true; 30 _authentication.userName = loginData.userName; 31 _authentication.fullName = response.data.FullName; 32 _authentication.roles = JSON.parse(response.data.Roles); 33 _authentication.isOffice = _.contains(_authentication.roles, "Office"); 34 _authentication.isCustomer = _.contains(_authentication.roles, "Customer"); 35 36 deferred.resolve(response); 37 38 },(function (err, status) { 39 _logOut(); 40 deferred.reject(err); 41 })); 42 43 return deferred.promise; 44 45 }; 46 47 var _logOut = function () { 48 49 localStorageService.remove('authorizationData'); 50 51 _authentication.isAuth = false; 52 _authentication.userName = ""; 53 _authentication.fullName = ""; 54 _authentication.roles = ""; 55 _authentication.isOffice = false; 56 _authentication.isCustomer = false; 57 58 }; 59 60 var _fillAuthData = function () { 61 62 var authData = localStorageService.get('authorizationData'); 63 if (authData) { 64 _authentication.isAuth = true; 65 _authentication.userName = authData.userName; 66 _authentication.fullName = authData.fullName; 67 _authentication.roles = authData.roles; 68 _authentication.isOffice = _.contains(_authentication.roles, "Office"); 69 _authentication.isCustomer = _.contains(_authentication.roles, "Customer"); 70 } 71 72 } 73 74 75 authServiceFactory.login = _login; 76 authServiceFactory.logOut = _logOut; 77 authServiceFactory.fillAuthData = _fillAuthData; 78 authServiceFactory.authentication = _authentication; 79 80 return authServiceFactory; 81 } 82})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.