Commit e9bfbb5d86e6ebbf7be35d81d924096d51f098a1
1 parent
02409a0b
Exists in
master
and in
5 other branches
Refactoring captcha and display captcha in forgot password form
Showing
2 changed files
with
37 additions
and
20 deletions
Show diff stats
index.html
... | ... | @@ -450,7 +450,7 @@ |
450 | 450 | </div> |
451 | 451 | </form> |
452 | 452 | |
453 | - <form id="forgot-password-form" class="forgot-password hide" autocomplete="off" method="post"> | |
453 | + <form id="forgot-password-form" class="forgot-password-form hide" autocomplete="off" method="post"> | |
454 | 454 | <p class="box-subtitle">Esqueceu sua senha?</p> |
455 | 455 | <div class="message alert-danger hide"></div> |
456 | 456 | <div class="row"> |
... | ... | @@ -460,6 +460,16 @@ |
460 | 460 | </div> |
461 | 461 | </div> |
462 | 462 | <div class="row"> |
463 | + <div id="serpro_captcha" class="captcha col-sm-12"> | |
464 | + </div> | |
465 | + <div class="captcha col-sm-12"> | |
466 | + Digite os caracteres acima: | |
467 | + </div> | |
468 | + <div class="captcha col-sm-6"> | |
469 | + <input type="text" name="captcha_text" id="captcha_text"> | |
470 | + </div> | |
471 | + </div> | |
472 | + <div class="row"> | |
463 | 473 | <div class="col-sm-4"> |
464 | 474 | <button type="submit" class="confirm-forgot-password button button-confirm button-block">Confirmar</button> |
465 | 475 | </div> | ... | ... |
js/main.js
... | ... | @@ -888,6 +888,25 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers |
888 | 888 | }); |
889 | 889 | }); |
890 | 890 | }, |
891 | + reloadCaptcha: function(element) { | |
892 | + var $element = $(element); | |
893 | + if($element.data('captcha')){ | |
894 | + $element.data('captcha').recarregar(); | |
895 | + } | |
896 | + }, | |
897 | + initCaptcha: function(element) { | |
898 | + var $element = $(element); | |
899 | + if($element.data('captcha')) return; | |
900 | + | |
901 | + $element.val(''); | |
902 | + var oCaptcha_serpro_gov_br = new captcha_serpro_gov_br(); | |
903 | + $element.data('captcha', oCaptcha_serpro_gov_br); | |
904 | + oCaptcha_serpro_gov_br.clienteId = serpro_captcha_clienteId; | |
905 | + if(!localDevelopment) { | |
906 | + oCaptcha_serpro_gov_br.url = "/captchaserpro" | |
907 | + } | |
908 | + oCaptcha_serpro_gov_br.criarUI(element, 'css', 'serpro_captcha_component_', Main.guid()); | |
909 | + }, | |
891 | 910 | computeBoxHeight: function(){ |
892 | 911 | var hPerLineOnTitle = 25; |
893 | 912 | var hPerLineOnParagraph = 20; |
... | ... | @@ -1376,12 +1395,14 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers |
1376 | 1395 | }); |
1377 | 1396 | }); |
1378 | 1397 | |
1379 | - $(document).on('click', '.forgot-password', function(e) { | |
1398 | + $(document).on('click', 'a.forgot-password', function(e) { | |
1380 | 1399 | var loginForm = $(this).parents('#login-form'); |
1381 | 1400 | var $forgotPasswordForm = loginForm.siblings('#forgot-password-form'); |
1382 | 1401 | loginForm.hide(); |
1383 | 1402 | $forgotPasswordForm.show(); |
1384 | 1403 | |
1404 | + Main.initCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | |
1405 | + | |
1385 | 1406 | var $message = $forgotPasswordForm.find('.message'); |
1386 | 1407 | $message.html(''); |
1387 | 1408 | $message.hide(); |
... | ... | @@ -1436,10 +1457,12 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers |
1436 | 1457 | $message.html('Verifique seu email para efetuar a troca da senha.'); |
1437 | 1458 | $message.show(); |
1438 | 1459 | }).fail(function() { |
1460 | + Main.reloadCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | |
1439 | 1461 | var $message = $forgotPasswordForm.find('.message'); |
1440 | 1462 | $message.html('Não foi possível requisitar a troca de senha para os dados informados.'); |
1441 | 1463 | $message.show(); |
1442 | 1464 | }); |
1465 | + e.preventDefault(); | |
1443 | 1466 | }); |
1444 | 1467 | |
1445 | 1468 | $(document).on('click', '.cancel-forgot-password', function(e) { |
... | ... | @@ -1450,11 +1473,6 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers |
1450 | 1473 | }); |
1451 | 1474 | |
1452 | 1475 | $(document).on('click', '.new-user', function(e) { |
1453 | - | |
1454 | - if(window.lastCaptcha){ | |
1455 | - window.lastCaptcha.destruir(); | |
1456 | - } | |
1457 | - | |
1458 | 1476 | var message = $('.signup .message'); |
1459 | 1477 | message.hide(); |
1460 | 1478 | message.text(''); |
... | ... | @@ -1483,15 +1501,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers |
1483 | 1501 | signupForm.find('#captcha_text').val(''); |
1484 | 1502 | signupForm.find('#user_terms_accepted').removeAttr('checked'); |
1485 | 1503 | |
1486 | - | |
1487 | - var oCaptcha_serpro_gov_br; | |
1488 | - oCaptcha_serpro_gov_br = new captcha_serpro_gov_br(); | |
1489 | - window.lastCaptcha = oCaptcha_serpro_gov_br; | |
1490 | - oCaptcha_serpro_gov_br.clienteId = serpro_captcha_clienteId; | |
1491 | - if(!localDevelopment) { | |
1492 | - oCaptcha_serpro_gov_br.url = "/captchaserpro" | |
1493 | - } | |
1494 | - oCaptcha_serpro_gov_br.criarUI(signupForm.find('#serpro_captcha')[0], 'css', 'serpro_captcha_component_'); | |
1504 | + Main.initCaptcha(signupForm.find('#serpro_captcha')[0]); | |
1495 | 1505 | |
1496 | 1506 | e.preventDefault(); |
1497 | 1507 | }); |
... | ... | @@ -1621,10 +1631,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers |
1621 | 1631 | }) |
1622 | 1632 | .fail(function (data) { |
1623 | 1633 | var msg = ''; |
1624 | - // Reload captcha here | |
1625 | - if(window.lastCaptcha){ | |
1626 | - window.lastCaptcha.recarregar(); | |
1627 | - } | |
1634 | + Main.reloadCaptcha($signupForm.find('#serpro_captcha')[0]); | |
1628 | 1635 | |
1629 | 1636 | if(data.responseJSON){ |
1630 | 1637 | try{ | ... | ... |