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,7 +450,7 @@ | ||
450 | </div> | 450 | </div> |
451 | </form> | 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 | <p class="box-subtitle">Esqueceu sua senha?</p> | 454 | <p class="box-subtitle">Esqueceu sua senha?</p> |
455 | <div class="message alert-danger hide"></div> | 455 | <div class="message alert-danger hide"></div> |
456 | <div class="row"> | 456 | <div class="row"> |
@@ -460,6 +460,16 @@ | @@ -460,6 +460,16 @@ | ||
460 | </div> | 460 | </div> |
461 | </div> | 461 | </div> |
462 | <div class="row"> | 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 | <div class="col-sm-4"> | 473 | <div class="col-sm-4"> |
464 | <button type="submit" class="confirm-forgot-password button button-confirm button-block">Confirmar</button> | 474 | <button type="submit" class="confirm-forgot-password button button-confirm button-block">Confirmar</button> |
465 | </div> | 475 | </div> |
js/main.js
@@ -888,6 +888,25 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -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 | computeBoxHeight: function(){ | 910 | computeBoxHeight: function(){ |
892 | var hPerLineOnTitle = 25; | 911 | var hPerLineOnTitle = 25; |
893 | var hPerLineOnParagraph = 20; | 912 | var hPerLineOnParagraph = 20; |
@@ -1376,12 +1395,14 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -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 | var loginForm = $(this).parents('#login-form'); | 1399 | var loginForm = $(this).parents('#login-form'); |
1381 | var $forgotPasswordForm = loginForm.siblings('#forgot-password-form'); | 1400 | var $forgotPasswordForm = loginForm.siblings('#forgot-password-form'); |
1382 | loginForm.hide(); | 1401 | loginForm.hide(); |
1383 | $forgotPasswordForm.show(); | 1402 | $forgotPasswordForm.show(); |
1384 | 1403 | ||
1404 | + Main.initCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | ||
1405 | + | ||
1385 | var $message = $forgotPasswordForm.find('.message'); | 1406 | var $message = $forgotPasswordForm.find('.message'); |
1386 | $message.html(''); | 1407 | $message.html(''); |
1387 | $message.hide(); | 1408 | $message.hide(); |
@@ -1436,10 +1457,12 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1436,10 +1457,12 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
1436 | $message.html('Verifique seu email para efetuar a troca da senha.'); | 1457 | $message.html('Verifique seu email para efetuar a troca da senha.'); |
1437 | $message.show(); | 1458 | $message.show(); |
1438 | }).fail(function() { | 1459 | }).fail(function() { |
1460 | + Main.reloadCaptcha($forgotPasswordForm.find('#serpro_captcha')[0]); | ||
1439 | var $message = $forgotPasswordForm.find('.message'); | 1461 | var $message = $forgotPasswordForm.find('.message'); |
1440 | $message.html('Não foi possível requisitar a troca de senha para os dados informados.'); | 1462 | $message.html('Não foi possível requisitar a troca de senha para os dados informados.'); |
1441 | $message.show(); | 1463 | $message.show(); |
1442 | }); | 1464 | }); |
1465 | + e.preventDefault(); | ||
1443 | }); | 1466 | }); |
1444 | 1467 | ||
1445 | $(document).on('click', '.cancel-forgot-password', function(e) { | 1468 | $(document).on('click', '.cancel-forgot-password', function(e) { |
@@ -1450,11 +1473,6 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1450,11 +1473,6 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
1450 | }); | 1473 | }); |
1451 | 1474 | ||
1452 | $(document).on('click', '.new-user', function(e) { | 1475 | $(document).on('click', '.new-user', function(e) { |
1453 | - | ||
1454 | - if(window.lastCaptcha){ | ||
1455 | - window.lastCaptcha.destruir(); | ||
1456 | - } | ||
1457 | - | ||
1458 | var message = $('.signup .message'); | 1476 | var message = $('.signup .message'); |
1459 | message.hide(); | 1477 | message.hide(); |
1460 | message.text(''); | 1478 | message.text(''); |
@@ -1483,15 +1501,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1483,15 +1501,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
1483 | signupForm.find('#captcha_text').val(''); | 1501 | signupForm.find('#captcha_text').val(''); |
1484 | signupForm.find('#user_terms_accepted').removeAttr('checked'); | 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 | e.preventDefault(); | 1506 | e.preventDefault(); |
1497 | }); | 1507 | }); |
@@ -1621,10 +1631,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1621,10 +1631,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
1621 | }) | 1631 | }) |
1622 | .fail(function (data) { | 1632 | .fail(function (data) { |
1623 | var msg = ''; | 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 | if(data.responseJSON){ | 1636 | if(data.responseJSON){ |
1630 | try{ | 1637 | try{ |