Commit 9a16a9d224ac196d034e5babbf575af9068a78ba
1 parent
3c9ae4e6
Exists in
master
and in
5 other branches
Added change password form
Showing
2 changed files
with
76 additions
and
2 deletions
Show diff stats
index.html
| @@ -422,6 +422,32 @@ | @@ -422,6 +422,32 @@ | ||
| 422 | </div> | 422 | </div> |
| 423 | </form> | 423 | </form> |
| 424 | 424 | ||
| 425 | + <form id="new-password-form" class="new-password hide" autocomplete="off" method="post"> | ||
| 426 | + <p class="box-subtitle">Trocar senha</p> | ||
| 427 | + <div class="message alert-danger hide"></div> | ||
| 428 | + <div class="row"> | ||
| 429 | + <div class="value col-sm-12"> | ||
| 430 | + <label for="new-password" class="label">Informe a nova senha:</label> | ||
| 431 | + <input id="new-password" name="password" type="password" required placeholder="Nova senha"> | ||
| 432 | + </div> | ||
| 433 | + </div> | ||
| 434 | + <div class="row"> | ||
| 435 | + <div class="value col-sm-12"> | ||
| 436 | + <label for="new-password-confirmation" class="label">Confirme a nova senha:</label> | ||
| 437 | + <input id="new-password-confirmation" name="password_confirmation" type="password" required placeholder="Confirmação da senha"> | ||
| 438 | + </div> | ||
| 439 | + <input type="hidden" id="new-password-code" name="code"> | ||
| 440 | + </div> | ||
| 441 | + <div class="row"> | ||
| 442 | + <div class="col-sm-4"> | ||
| 443 | + <button type="submit" class="confirm-new-password button button-confirm button-block">Confirmar</button> | ||
| 444 | + </div> | ||
| 445 | + <div class="col-sm-4"> | ||
| 446 | + <button type="button" class="cancel-new-password button button-cancela button-block">Cancelar</button> | ||
| 447 | + </div> | ||
| 448 | + </div> | ||
| 449 | + </form> | ||
| 450 | + | ||
| 425 | <form id="forgot-password-form" class="forgot-password hide" autocomplete="off" method="post"> | 451 | <form id="forgot-password-form" class="forgot-password hide" autocomplete="off" method="post"> |
| 426 | <p class="box-subtitle">Esqueceu sua senha?</p> | 452 | <p class="box-subtitle">Esqueceu sua senha?</p> |
| 427 | <div class="message alert-danger hide"></div> | 453 | <div class="message alert-danger hide"></div> |
js/main.js
| @@ -594,6 +594,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -594,6 +594,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 594 | var regexResultados = /resultados$/; | 594 | var regexResultados = /resultados$/; |
| 595 | var regexSobreOPrograma = /sobre-o-programa$/; | 595 | var regexSobreOPrograma = /sobre-o-programa$/; |
| 596 | var regexActivateUser = /#\/activate/; | 596 | var regexActivateUser = /#\/activate/; |
| 597 | + var regexChangeUserPassword = /#\/trocar_senha/; | ||
| 597 | 598 | ||
| 598 | if( (regexHideBarra.exec(hash) === null) && !HIDE_BARRA_DO_GOVERNO ){ | 599 | if( (regexHideBarra.exec(hash) === null) && !HIDE_BARRA_DO_GOVERNO ){ |
| 599 | this.addBarraDoGoverno(); | 600 | this.addBarraDoGoverno(); |
| @@ -612,6 +613,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -612,6 +613,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 612 | var isResultados = regexResultados.exec(hash) !== null; | 613 | var isResultados = regexResultados.exec(hash) !== null; |
| 613 | var isSobreOPrograma = regexSobreOPrograma.exec(hash) !== null; | 614 | var isSobreOPrograma = regexSobreOPrograma.exec(hash) !== null; |
| 614 | var isActivateUser = regexActivateUser.exec(hash) !== null; | 615 | var isActivateUser = regexActivateUser.exec(hash) !== null; |
| 616 | + var isChangeUserPassword = regexChangeUserPassword.exec(hash) !== null; | ||
| 615 | 617 | ||
| 616 | if(isArticle) { | 618 | if(isArticle) { |
| 617 | this.display_article(hash.split('/')[2], lastHash); | 619 | this.display_article(hash.split('/')[2], lastHash); |
| @@ -688,6 +690,11 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -688,6 +690,11 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 688 | Main.activateUser(code); | 690 | Main.activateUser(code); |
| 689 | } | 691 | } |
| 690 | 692 | ||
| 693 | + if(isChangeUserPassword){ | ||
| 694 | + var code = parts.pop(); | ||
| 695 | + Main.changeUserPassword(code); | ||
| 696 | + } | ||
| 697 | + | ||
| 691 | // [BEGIN] Tracking | 698 | // [BEGIN] Tracking |
| 692 | if (window._paq){ | 699 | if (window._paq){ |
| 693 | // _paq.push(['trackEvent', 'NavegarPara', hash || '/']); | 700 | // _paq.push(['trackEvent', 'NavegarPara', hash || '/']); |
| @@ -944,6 +951,15 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -944,6 +951,15 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 944 | handleLoginFail: function (e){ | 951 | handleLoginFail: function (e){ |
| 945 | console.error('handleLoginFail', e); | 952 | console.error('handleLoginFail', e); |
| 946 | }, | 953 | }, |
| 954 | + changeUserPassword: function(code){ | ||
| 955 | + if(!code || code.length == 0) return; | ||
| 956 | + var $loginPanel = $('#login-panel'); | ||
| 957 | + $loginPanel.show(); | ||
| 958 | + $loginPanel.find('#login-form').hide(); | ||
| 959 | + var $newPasswordForm = $loginPanel.find('#new-password-form'); | ||
| 960 | + $newPasswordForm.find('#new-password-code').val(code); | ||
| 961 | + $newPasswordForm.show(); | ||
| 962 | + }, | ||
| 947 | activateUser: function(code){ | 963 | activateUser: function(code){ |
| 948 | 964 | ||
| 949 | /** | 965 | /** |
| @@ -1052,8 +1068,6 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1052,8 +1068,6 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 1052 | $('.login-container').html(loginTemplate()); | 1068 | $('.login-container').html(loginTemplate()); |
| 1053 | $('.countdown').maxlength({text: '%left caracteres restantes'}); | 1069 | $('.countdown').maxlength({text: '%left caracteres restantes'}); |
| 1054 | 1070 | ||
| 1055 | - Main.navigateTo(window.location.hash); | ||
| 1056 | - | ||
| 1057 | $(document).on('click', '.oauth-login', function (e){ | 1071 | $(document).on('click', '.oauth-login', function (e){ |
| 1058 | Main.oauthClientAction($(this).attr('href')); | 1072 | Main.oauthClientAction($(this).attr('href')); |
| 1059 | e.preventDefault(); | 1073 | e.preventDefault(); |
| @@ -1112,6 +1126,8 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1112,6 +1126,8 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 1112 | $('.participar').removeClass('hide'); | 1126 | $('.participar').removeClass('hide'); |
| 1113 | })(); | 1127 | })(); |
| 1114 | 1128 | ||
| 1129 | + Main.navigateTo(window.location.hash); | ||
| 1130 | + | ||
| 1115 | //Actions for links | 1131 | //Actions for links |
| 1116 | $( '#nav-proposal-categories a' ).on('click', function(e){ | 1132 | $( '#nav-proposal-categories a' ).on('click', function(e){ |
| 1117 | e.preventDefault(); | 1133 | e.preventDefault(); |
| @@ -1374,6 +1390,38 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -1374,6 +1390,38 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 1374 | e.preventDefault(); | 1390 | e.preventDefault(); |
| 1375 | }); | 1391 | }); |
| 1376 | 1392 | ||
| 1393 | + $(document).on('click', '.cancel-new-password', function(e) { | ||
| 1394 | + var newPasswordForm = $(this).parents('#new-password-form'); | ||
| 1395 | + var loginForm = newPasswordForm.siblings('#login-form'); | ||
| 1396 | + loginForm.show(); | ||
| 1397 | + newPasswordForm.hide(); | ||
| 1398 | + }); | ||
| 1399 | + | ||
| 1400 | + $(document).on('click', '.confirm-new-password', function(e) { | ||
| 1401 | + var $newPasswordForm = $(this).parents('#new-password-form'); | ||
| 1402 | + $.ajax({ | ||
| 1403 | + method: 'PATCH', | ||
| 1404 | + url:host+'/api/v1/new_password', | ||
| 1405 | + data: { | ||
| 1406 | + code: $newPasswordForm.find('#new-password-code').val(), | ||
| 1407 | + password: $newPasswordForm.find('#new-password').val(), | ||
| 1408 | + password_confirmation: $newPasswordForm.find('#new-password-confirmation').val() | ||
| 1409 | + }, | ||
| 1410 | + }).done(function(data) { | ||
| 1411 | + $newPasswordForm.find('.cancel-new-password').click(); | ||
| 1412 | + var $message = $newPasswordForm.siblings('#login-form').find('.message-success'); | ||
| 1413 | + $message.html('Senha alterada com sucesso.'); | ||
| 1414 | + $message.show(); | ||
| 1415 | + Main.loginCallback(data.activated, data.private_token, data); | ||
| 1416 | + window.location.hash = '/'; | ||
| 1417 | + }).fail(function() { | ||
| 1418 | + var $message = $newPasswordForm.find('.message'); | ||
| 1419 | + $message.html('Não foi possível trocar a senha com os dados informados.'); | ||
| 1420 | + $message.show(); | ||
| 1421 | + }); | ||
| 1422 | + e.preventDefault(); | ||
| 1423 | + }); | ||
| 1424 | + | ||
| 1377 | $(document).on('click', '.confirm-forgot-password', function(e) { | 1425 | $(document).on('click', '.confirm-forgot-password', function(e) { |
| 1378 | var $forgotPasswordForm = $(this).parents('#forgot-password-form'); | 1426 | var $forgotPasswordForm = $(this).parents('#forgot-password-form'); |
| 1379 | var $inputValue = $forgotPasswordForm.find('#forgot-password-value'); | 1427 | var $inputValue = $forgotPasswordForm.find('#forgot-password-value'); |