PageSourceSearch

https://tmcdiscos.com.br/funcao/login.js?v=1

js tmcdiscos.com.br collected 2026-09-27 16:02:43 UTC 11,886 bytes, 306 lines download raw bytes

1/* /arquivos/js/login.js */
2
3(function($, window, document){
4  'use strict';
5
6  // ========= Helpers =========
7
8  function runRecaptchaV3(action, $form, done) {
9    if (!window.grecaptcha || !window.APP || !APP.siteKey) {
10      console.error('reCAPTCHA v3 não carregado ou siteKey ausente.');
11      if (typeof done === 'function') done(); // fallback: segue sem token (não recomendado)
12      return;
13    }
14    grecaptcha.ready(function() {
15      grecaptcha.execute(APP.siteKey, {action: action}).then(function(token) {
16        if (!$form.find('input[name="g-recaptcha-response"]').length) {
17          $form.append('<input type="hidden" name="g-recaptcha-response">');
18        }
19        $form.find('input[name="g-recaptcha-response"]').val(token);
20
21        if (typeof done === 'function') done();
22      });
23    });
24  }
25
26  function setKey($form){
27    var url = ($form.data('key-endpoint') || (APP && APP.endpoints && APP.endpoints.key) || 'json/key.php');
28    $.get(url, function(html){
29      $form.find('.loadKey').html(html).show();
30      $form.find('input[name="key"]').val('');
31    });
32  }
33
34  /* Validação já existente no projeto (usa sua função global)
35  function validaCampos(formEl, regras) {
36    if (typeof window.valida_form === 'function') {
37      return window.valida_form(formEl, regras, false);
38    }
39    // fallback simples
40    return true;
41  }
42    */
43
44  // Monta o bloco de redefinição (igual ao seu, só que aqui no .js)
45  function renderResetPanel() {
46    $('#respostaReset').closest('.eng-login-cadastro').remove();
47
48    var emailVal = $('#Email').val() || (APP && APP.defaultEmail) || '';
49
50    var html =
51    '<div class="content eng-login-cadastro"><div class="caixaTextoBorda">'+
52      '<div class="clearfix"></div>' +
53      '<div class="caixaTexto  content-white">'+
54      '<div id="respostaReset" class="panel panel-success " style="margin-top:15px;">' +
55      '  <div class="panel-heading informe">' +
56      '    <span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Redefinir senha' +
57      '  </div>' +
58      '  <div class="panel-body">' +
59      '    <p class="text-muted alert alert-warning enviamos_codigo">Enviamos um código de validação para o seu e-mail.</p>' +
60      '    <form id="formResetInline" class="form-horizontal" role="form" onsubmit="return false;" autocomplete="off" data-endpoint="'+ ($('#id_form_login').data('endpoint') || (APP && APP.endpoints && APP.endpoints.login) || 'json/login.php') +'" data-key-endpoint="'+ ($('#id_form_login').data('key-endpoint') || (APP && APP.endpoints && APP.endpoints.key) || 'json/key.php') +'">' +
61
62      '      <input type="hidden" name="Email" id="EmailResetHidden" value="'+ $('<div>').text(emailVal).html() +'">' +
63      '      <input type="hidden" name="acao" id="acao_tipo_reset" value="alterar_senha">' +
64
65      '      <div class="form-group input label-input">' +
66      '        <label for="alteracao_codigo" class="col-sm-3 control-label">Código</label>' +
67      '        <div class="col-sm-6">' +
68      '          <input type="text" class="form-control" id="alteracao_codigo" name="Codigo" placeholder="Código recebido no E-mail" autocomplete="one-time-code" maxlength="8">' +
69      '        </div>' +
70      '      </div>' +
71
72      '      <div class="form-group input label-input">' +
73      '        <label for="SenhaReset" class="col-sm-3 control-label">Nova senha</label>' +
74      '        <div class="col-sm-6">' +
75      '          <input type="password" class="form-control" id="SenhaReset" name="Senha" placeholder="Informe a nova senha" autocomplete="new-password">' +
76      '        </div>' +
77      '      </div>' +
78
79      '      <div class="form-group input label-input">' +
80      '        <label for="SenhaReset1" class="col-sm-3 control-label">Repita a senha</label>' +
81      '        <div class="col-sm-6">' +
82      '          <input type="password" class="form-control" id="SenhaReset1" name="Senha1" placeholder="Repita a senha" autocomplete="new-password">' +
83      '        </div>' +
84      '      </div>' +
85
86      '      <div id="div_captcha_inline" class="hide div_captcha">' +
87      '        <div class="form-group input label-input">' +
88      '          <label class="col-sm-3 control-label">Código de Segurança</label>' +
89      '          <div class="col-sm-6">' +
90      '            <div class="loadKey"></div>' +
91      '            <div class="help-block" style="margin:3px 0 6px">Repita o número da imagem</div>' +
92      '            <input type="text" placeholder="Repita o número" name="key" maxlength="4" class="numero form-control key">' +
93      '          </div>' +
94      '        </div>' +
95      '      </div>' +
96
97      '      <div class="form-group input label-input botoes">' +
98      '        <div class="col-sm-6 col-sm-offset-3">' +
99      '          <input type="button" id="btnResetContinue" class="botao bot_continuar  btn btn-primary btn-block" value="Continuar">' +
100      '          <p class="help-block" style="margin-top:8px;">O código expira em até 10 minutos.</p>' +
101      '        </div>' +
102      '      </div>' +
103
104      '    </form>' +
105      '  </div>' +
106      '</div>' +
107    '</div></div></div>';
108
109    $('#id_form_login').parent().append(html);
110
111    $('#alteracao_codigo').focus();
112    if(modelo_loja.includes('m19')==false)
113      $('html, body').animate({ scrollTop: $('#respostaReset').offset().top - 100 }, 300);
114    else
115      $('html, body').animate({ scrollTop: $('#respostaReset').offset().top - 400 }, 300);
116
117    // Enter envia
118    $(document).off('keypress', '#formResetInline input')
119      .on('keypress', '#formResetInline input', function (e) {
120        if (e.which === 13) $('#btnResetContinue').click();
121      });
122      
123  }
124   
125  // ========= Ações (antes inline) =========
126
127  function alteracao_codigo_btn(){
128    $('#respostaSenha').remove();
129
130    var regras = [
131      [ ['Email'],      'E-mail','email' ],
132      [ ['Codigo'],     'Código' ],
133      [ ['SenhaReset'], 'Senha', 'password' ]
134    ];
135
136    if ($('#formResetInline .div_captcha').is(':visible')) {
137      regras.push([ ['key'], 'Código de Segurança' ]);
138    }
139
140    var ok = valida_form(document.getElementById('formResetInline'), regras, false);
141    if (!ok) return;
142
143    var $form = $('#formResetInline');
144    var url   = $form.data('endpoint') || (APP && APP.endpoints && APP.endpoints.login) || 'json/login.php';
145
146    $.ajax({
147      type: "POST",
148      url: url,
149      data: $form.serialize(),
150      success: function(data){
151        var aux = {};
152        try { aux = $.parseJSON(data); } catch(e){ aux = {status:-1, msg:'Falha ao decodificar resposta.'}; }
153
154        if(aux.status >0 ){
155          $('#respostaReset').html('<div id="respostaSenha" class="alert alert-success">'+ (aux.msg||'') +'</div>');
156          return true;
157
158        }
159        if (aux.status < 0 && aux.status > -5){
160          $form.find('.div_captcha').removeClass('hide');
161          setKey($form);
162        }
163        $('#div_captcha_inline').after('<div id="respostaSenha" class="alert alert-danger">'+ (aux.msg||'') +'</div>');
164      }
165    });
166  }
167
168  function envia_form1(){
169    $('#respostaLogin').remove();
170
171    var regras = [
172      [ ['Email'], 'E-mail','email' ],
173      [ ['Senha'], 'Senha' ]
174    ];
175
176    var acao = $('#acao_tipo').val();
177    if (acao === 'esqueci') {
178      regras.splice(1, 1); // remove senha
179    }
180
181    if ($('#id_form_login .div_captcha').is(':visible')) {
182      regras.push([ ['key'], 'Código de Segurança' ]);
183    }
184
185    var ok = valida_form(document.getElementById('id_form_login'), regras, false);
186    if (!ok) return;
187
188    var $form = $('#id_form_login');
189    var url   = $form.data('endpoint') || (APP && APP.endpoints && APP.endpoints.login) || 'json/login.php';
190
191    $.ajax({
192      type: "POST",
193      url: url,
194      data: $form.serialize(),
195      success: function(data){
196        var aux = {};
197        try { aux = $.parseJSON(data); } catch(e){ aux = {status:-1, msg:'Falha ao decodificar resposta.'}; }
198        console.log(aux);
199        if (aux.status <= 0){
200          $('.eng-login-cadastro').first().before('<div id="respostaLogin" class="alert alert-danger">'+ (aux.msg||'') +'</div>');
201
202          if (aux.status < 0){
203            if (aux.status > -5) { // erro de recaptcha
204              $('#id_form_login .div_captcha').removeClass('hide');
205            }
206            if ($('#id_form_login .div_captcha').is(':visible')) {
207              setKey($form);
208            }
209            if(aux.status=='-5'){
210              $('#esqueci').click(function (e) { 
211                e.preventDefault();
212                $('#link_esqueci').click();
213                
214              });
215              
216            }
217          }
218        } else {
219          // sucesso
220          if (acao !== 'esqueci') {
221            //login no sistema            
222            if (APP && APP.pixel) { try { fbq && fbq('track','Login Efetuado'); } catch(_e){} }
223            if(aux.status=='3'){
224              alert('Sua senha esta expirando! Altere imediatamente para não ficar sem acesso.') ;
225              window.open('novo_cliente.php?aba=3','_self');
226              return true;
227            }            
228            if (aux && aux.dados && aux.dados.ShopperID) window.open('carrinho.php?ShopperID='+aux.dados.ShopperID,'_self');
229            else if (APP && APP.redirects && APP.redirects.finalizar) window.open('finalizar.php','_self');
230            else if (APP && APP.redirects && APP.redirects.carrinho)  window.open('carrinho.php','_self');
231            else window.open('cliente_informacoes.php','_self');
232          } else {
233            //esqueci minha senha
234            // monta painel de redefinição
235            renderResetPanel();
236            if(aux.dados != undefined && aux.dados.email!= undefined)
237              $('#respostaReset').before(aux.dados.email)
238
239            // bind do botão "Continuar" com recaptcha v3 (action: alterar_senha)
240            $(document).off('click', '#btnResetContinue').on('click', '#btnResetContinue', function(e){
241              e.preventDefault();
242              runRecaptchaV3('alterar_senha', $('#formResetInline'), function(){
243                alteracao_codigo_btn(); 
244              });
245            });
246
247            // Enter envia no painel (já configurado dentro do render)
248          }
249        }
250      }
251    });
252  }
253
254  // ========= Eventos (document ready) =========
255  $(function(){
256
257    // Pré-preenche e-mail, se houver na config
258    if (APP && APP.defaultEmail && !$('#Email').val()) {
259      $('#Email').val(APP.defaultEmail);
260    }
261
262    // "Esqueci minha senha"
263    $(document).off('click', '#link_esqueci').on('click', '#link_esqueci', function (e) {
264      e.preventDefault();
265      $('#acao_tipo').val('esqueci');
266      runRecaptchaV3('esqueci', $('#id_form_login'), function(){
267        envia_form1();
268      });
269    
270      $('.div_captcha .bot_continuar').off().click(function (e) { 
271        e.preventDefault();
272        $('#link_esqueci').click();
273        
274      });
275    });
276
277    // Botão "Entrar"
278    $(document).on('click', '#btn_submit', function (e) {
279      e.preventDefault();
280      $('#acao_tipo').val('login'); // login normal
281      runRecaptchaV3('login', $('#id_form_login'), function(){
282        envia_form1();
283      });
284       $('.div_captcha .bot_continuar').off().click(function (e) { 
285        e.preventDefault();
286        $('#btn_submit').click();
287        
288      });
289    });
290
291  });
292    $(document).on('keypress', '#id_form_login #Email, #id_form_login #Senha', function (e) {       
293        if (e.which === 13) {$('#btn_submit').click(); return false;}
294       
295      });
296  
297  window.runRecaptchaV3 = runRecaptchaV3;
298  window.setKey = setKey;
299  window.renderResetPanel = renderResetPanel;
300  window.alteracao_codigo_btn = alteracao_codigo_btn;
301  // (opcional) também pelo APP:
302  window.APP = window.APP || {};
303  APP.runRecaptchaV3 = runRecaptchaV3;
304  APP.setKey = setKey;
305
306})(jQuery, window, document);

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.