PageSourceSearch

http://cloudsenior.grupotecnoseg.com.br:8180/mgepes/html5/PortalRH/LoginBody/NewLogin.js

js grupotecnoseg.com.br collected 2026-10-04 20:37:10 UTC 11,371 bytes, 268 lines download raw bytes

1angular
2    .module("LoginRHApp", ["folha","ngMaterial","ngMessages"])
3    .controller("LoginController", ["$scope", 'FolhaProxy', "$mdDialog", "PopupServiceMat","FeatureFlagService", "StringUtils",
4    function($scope, FolhaProxy, $mdDialog, PopupServiceMat, FeatureFlagService, StringUtils){
5        $scope.usuario;
6        $scope.senha;
7        $scope.isActiveFeatureFlagKeycloak = false;
8        $scope.isLoadingSankhyaPass = false;
9        $scope.inputType = 'password';
10        $scope.showPassword = false;
11
12        $(document).ready(()=>{
13            $scope.init();
14        });
15
16        $scope.init = function(){
17            $($(document).find('body')[0]).attr('theme', 'light');
18
19            document.querySelector("#inputUser").addEventListener("keyup", event => {
20                if(event.key !== "Enter") return;
21                $scope.validaLogin();
22                event.preventDefault();
23            });
24
25            document.querySelector("#inputSenha").addEventListener("keyup", event => {
26                if(event.key !== "Enter") return;
27                $scope.validaLogin();
28                event.preventDefault();
29            });
30
31            $scope.getPublicKey();
32            $scope.isLoadingSankhyaPass = localStorage.getItem('sankhyaPassLogin') == 'true';
33            $scope.verificaFeatureFlagKeycloack();
34        }
35
36        $scope.verificaFeatureFlagKeycloack = function() {
37            FolhaProxy.callService('[email protected]').then(result => {
38                $scope.isActiveFeatureFlagKeycloak = result?.responseBody?.usaFeatureFlag;
39                $scope.inicializarKeycloak();
40            });
41        }
42
43        $scope.togglePasswordVisibility = function() {
44            $scope.showPassword = !$scope.showPassword;
45            $scope.inputType = $scope.showPassword ? 'text' : 'password';
46        };
47
48        $scope.inicializarKeycloak = async function () {
49
50            if (!$scope.isActiveFeatureFlagKeycloak) {
51                localStorage.removeItem('sankhyaPassLogin');
52                $scope.isLoadingSankhyaPass = false;
53                return;
54            }
55
56            await FolhaProxy.callService('[email protected]',{
57                }).then(result => {
58                    $scope.isProducao = result.responseBody.isProducao;
59                });
60
61            const configPath = $scope.isProducao 
62                ? './keycloak-config-prod.json' 
63                : './keycloak-config-dev.json';
64
65            fetch(configPath)
66                .then(response => response.json())
67                .then(config => {
68                    $scope.keycloak = new Keycloak({
69                        url: config.url,
70                        realm: config.realm,
71                        clientId: config.clientId
72                    });
73
74                    return $scope.keycloak.init({
75                        onLoad: 'check-sso',
76                        checkLoginIframe: false,
77                        pkceMethod: 'S256',
78                        silentCheckSsoRedirectUri: `${window.location.protocol}//${window.location.host}/mgepes/html5/PortalRH/LoginBody/auth.html`,
79                    });
80                })
81                .then(function (authenticated) {
82                    if (authenticated) {
83                        loginSankhyaPass($scope.keycloak.token);
84                    }else {
85                        $scope.isLoadingSankhyaPass = false;
86                    }
87                    $scope.keycloakInitialized = true;
88                    $scope.$apply();
89                })
90                .catch(function (err) {
91                    console.error("Erro ao inicializar Keycloak:", err);
92                });
93        };
94
95
96        $scope.keycloakLogin = function () {
97            if($scope.keycloakInitialized){
98                localStorage.setItem('sankhyaPassLogin', true);
99                $scope.keycloak.login();
100            }
101        }
102
103        // SERVICOS ====================================================================================================================== SERVICOS
104        {
105            // REALIZA LOGIN NO PORTALRH
106            $scope.validaLogin = function() {
107
108                FolhaProxy.callService('[email protected]',{
109                    usuario: $scope.usuario,
110                    encryptedSenha: encryptPassword($scope.senha)
111                }).then(result => {
112                    localStorage.setItem('sankhyaPassLogin', false);
113                    processaResultadoLogin(result);
114                });
115            }
116
117            // ENVIA SENHA NOVA PARA O EMIAL DO USUARIO
118            $scope.recuperarSenha = function(cpf){
119                FolhaProxy.callService('[email protected]',{
120                    'usuario': cpf
121                }).then(result => {
122                    if(!result.responseBody.error){
123                        PopupServiceMat.showPopup({title: 'Senha envi
123ada :)', content: 'Sua nova senha foi enviada com sucesso para o e-mail* \\'
124                        + result.responseBody.email + '\\ *'});
125                    }
126                });
127            }
128
129            function loginSankhyaPass(tokenSankhyaPass){
130                FolhaProxy.callService('[email protected]',{
131                    tokenSankhyaPass
132                }).then(result => {
133                    $scope.$apply(() => {
134                        $scope.usuario = result.responseBody.usuario;
135                    });
136                    processaResultadoLogin(result);
137                }, error => {
138                    $scope.$apply(() => {
139                        $scope.isLoadingSankhyaPass = false;
140                        $scope.keycloak.logout();
141                    });
142                });
143            }
144
145            function processaResultadoLogin(result) {
146                if(result.responseBody.loginValido){
147                    localStorage.setItem('cpfLogado', $scope.usuario);
148                    localStorage.setItem("sessao", JSON.stringify(result.responseBody.sessao));
149                    window.location.assign(result.responseBody.redirect);
150                }else{
151                    if(result.responseBody.possuiProduto){
152                        PopupServiceMat.showPopup({title: 'Ops :(', content: 'Usuário e/ou senha incorretos.'});
153                    }else{
154                        PopupServiceMat.showPopup({title: 'Ops :(', content: 'Você não pode acessar este produto.'});
155                    }
156                }
157            }
158        }
159        //=========================================================================================================================================
160
161        // POPUP RECUPERACAO SENHA ======================================================================================== POPUP RECUPERACAO SENHA
162        {
163            // ABRE POPUP DE RECUPERACAO DE SENHA
164            $scope.recuperarSenhaPopup = function(){
165                $mdDialog.show({
166                    controller: recuperarSenhaPopupController,
167                    templateUrl: './LoginBody/popups/recuperarSenhaPopup.html',
168                    parent: angular.element(document.body),
169                    locals: {
170                        usuario: $scope.usuario,
171                        testaCPF: $scope.testaCPF
172                    },
173                    clickOutsideToClose: true
174                }).then(function (answer) {
175                    $scope.recuperarSenha(answer);
176                });
177            }
178    
179            // CONTROLLER DA POPUP DE RECUPERACAO DE SENHA
180            function recuperarSenhaPopupController ($scope, $mdDialog, usuario, testaCPF){
181    
182                $scope.cpf = (angular.isDefined(usuario) && usuario != '')? usuario : undefined;
183                $scope.testaCPF = testaCPF;
184    
185                $scope.$on('closeAllDialogs', function(evt){
186                    $scope.hide();
187                });
188    
189                $scope.hide = function() {
190                    $mdDialog.hide();
191                };
192    
193                $scope.cancel = function() {
194                    $mdDialog.cancel();
195                };
196    
197                $scope.answer = function(answer) {
198                    $mdDialog.hide($scope.cpf);
199                };
200            }
201        }
202        //=========================================================================================================================================
203
204        // AUXILIARES ================================================================================================================== AUXILIARES
205        {
206            $scope.ehSessaoInvalida = function() {
207                var urlParams = new URLSearchParams(window.location.search);
208                if(urlParams.has('sessaoInvalida')){
209                    return true;
210                }
211                return false;
212            }
213
214            $scope.goToURL = function ( url ) {
215                window.location.href = url;
216            };
217
218            $scope.testaCPF = function(strCPF) {
219                Soma = 0;
220                if (strCPF == "00000000000" ||
221                    strCPF == "11111111111" ||
222                    strCPF == "22222222222" ||
223                    strCPF == "33333333333" ||
224                    strCPF == "44444444444" ||
225                    strCPF == "55555555555" ||
226                    strCPF == "66666666666" ||
227                    strCPF == "77777777777" ||
228                    strCPF == "88888888888" ||
229                    strCPF == "99999999999" ||
230                    strCPF == null) return false;
231                if(strCPF.length != 11) return false;
232                    
233                for (i=1; i<=9; i++) Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (11 - i);
234                Resto = (Soma * 10) % 11;
235                
236                    if ((Resto == 10) || (Resto == 11))  Resto = 0;
237                    if (Resto != parseInt(strCPF.substring(9, 10)) ) return false;
238                
239                Soma = 0;
240                    for (i = 1; i <= 10; i++) Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (12 - i);
241                    Resto = (Soma * 10) % 11;
242                
243                    if ((Resto == 10) || (Resto == 11))  Resto = 0;
244                    if (Resto != parseInt(strCPF.substring(10, 11) ) ) return false;
245                    return true;
246            }
247        }
248        //=========================================================================================================================================
249
250        // CRYPTO =================================================================================================================================
251        {
252
253            $scope.getPublicKey = ()=>{
254                FolhaProxy.callService('[email protected]', {})
255                .then(result => {
256                    $scope.publicKey = result.responseBody.publicKey;
257                });
258            }
259
260            function encryptPassword(text){
261                let encryptor = new JSEncrypt();
262                encryptor.setPublicKey($scope.publicKey);
263                return encryptor.encrypt(text);
264            }
265        }
266        // ========================================================================================================================================
267
268    }]);

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.