1(function() { 2 'use strict'; 3 4 function LoginByProxy(Base64, MozCookieSvc, principal, portalConfigService, Utils, exceptionService, accessService) { 5 6 /** 7 @desc validates input string 8 @param {string} desiredRole required, 'dealer' or 'customer' 9 @return {string} valid role string 10 */ 11 function vetDesiredRole (desiredRole) { 12 var typeString = Utils.getTypeString(desiredRole); 13 if (typeString !== 'string') { 14 throw exceptionService.invalidType('string', typeString); 15 } 16 17 desiredRole = desiredRole.trim().toLowerCase(); 18 if (desiredRole !== 'dealer' && desiredRole !== 'customer') { 19 throw exceptionService.invalidValue("'dealer' or 'customer'", desiredRole); 20 } 21 return desiredRole; 22 } // end vetDesiredRole 23 24 /** 25 @desc writes cookie with necessary proxy-request info and launches new tab/window 26 @param {string} desiredRole required, should be either 'dealer' or 'customer' 27 @param {object} selectedUser required, the target-user model 28 @return {void} 29 */ 30 function openSession(desiredRole, selectedUser) { 31 desiredRole = vetDesiredRole(desiredRole); 32 // console.log('selectedUser'); 33 // console.log(selectedUser); 34 var thePortalConfig = portalConfigService; 35 var serializedProxyRequest = ''; 36 var domain = ''; 37 var newUrl = ''; 38 var proxyWindow = null; 39 // var targetUserDealerId = $route.current.params.dealerId; 40 // var targetUserDealerId = portalConfig.helpGetDealerId(); 41 var targetUserDealerId = Utils.helpGetDealerId(); 42 var targetUserMostPrivilegedAccessRole = accessService.getMostPrivilegedRole(targetUserDealerId, selectedUser.dealerAccessRoles); 43 44 (function() { 45 var isPrivileged = false; 46 // var isInstaller = principal.identity().getRoles()[0].getUserType() === 'INSTALLER'; 47 var isInstaller = principal.identity().getUserType() === 'installer'; 48 49 if (isInstaller || (principal.identity().isLoginByProxyPrivileged())) { 50 isPrivileged = true; 51 } 52 53 var proxyRequest = { 54 targetUser: { 55 // dealerId: selectedUser.dealer.id, 56 dealerId: targetUserDealerId, 57 username: Base64.encode(selectedUser.username), 58 // userType: selectedUser.accessRoles[0].userType 59 userType: targetUserMostPrivilegedAccessRole.accessRole.userType 60 }, 61 proxyUser: { 62 username: sessionStorage.getItem('_authenticatedUsername'), 63 id: principal.identity().getId(), 64 // FIXME UUID 65 dealerId: thePortalConfig.getDealerId(), 66 privileged: isPrivileged, 67 userType: principal.identity().getUserType(), 68 firstName: principal.identity().getFirstName(), 69 lastName: principal.identity().getLastName(), 70 token: sessionStorage.getItem('X-AuthToken') 71 } 72 }; 73 74 serializedProxyRequest = JSON.stringify(proxyRequest); 75 })(); 76 77 (function() { 78 var hostnameArray = location.hostname.split('.'); 79 var port = location.port; 80 81 domain = hostnameArray[1] + '.' + hostnameArray[2]; 82 // TODO ? 83 // Provide a unique number attached to the 84 // loginbyproxy url and to the cookie key, such 85 // that the new window and cookie combo know that 86 // they belong to one another. 87 // newUrl = 'http://' + selectedUser.dealer.urlPrefix + 88 newUrl = 'http://' + targetUserMostPrivilegedAccessRole.dealer.urlPrefix + 89 '.' + domain + ':' + port + '/'; 90 })(); 91 92 MozCookieSvc.setItem( 93 'loginByProxy', 94 serializedProxyRequest, 95 10, 96 // The following param doesn't work, because the 97 // actual path seen by MozCookieSvc in the new 98 // session is '/', the following is an ng-path, 99 // which makes use of the hash portion of URLs. 100 // '/loginbyproxy', 101 '/', 102 '.' + domain 103 ); 104 105 proxyWindow = window.open(newUrl, '_blank'); 106 } // end openSession 107 108 return { 109 openSession: openSession 110 }; 111 } // end LoginByProxy 112 113 angular.module('authmodule').factory('LoginByProxySvc', LoginByProxy); 114}());
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.