Commit 3883e76d6091d80549b5f91e2b88d9915d6ed1a4
1 parent
4c7f555f
Exists in
master
and in
8 other branches
Refactoring oauth login
Showing
2 changed files
with
30 additions
and
5 deletions
Show diff stats
index.html
| ... | ... | @@ -333,8 +333,8 @@ |
| 333 | 333 | </div> |
| 334 | 334 | <div class="oauth"> |
| 335 | 335 | <div class="label">Acessar com:</div> |
| 336 | - <a href="/plugin/oauth_client/facebook?oauth_client_popup=true&id=1" target="_blank" class="facebook">Facebook</a> | |
| 337 | - <a href="/plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=2" target="_blank" class="google">Google +</a> | |
| 336 | + <a href="http://www.participa.br/plugin/oauth_client/facebook?oauth_client_popup=true&id=1" target="_blank" class="facebook oauth-login">Facebook</a> | |
| 337 | + <a href="http://www.participa.br//plugin/oauth_client/google_oauth2?oauth_client_popup=true&id=2" target="_blank" class="google oauth-login">Google +</a> | |
| 338 | 338 | <a href="http://www.participa.br/account/signup" target="_blank" class="new-user">Cadastrar</a> |
| 339 | 339 | </div> |
| 340 | 340 | </form> | ... | ... |
js/main.js
| ... | ... | @@ -43,6 +43,11 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 43 | 43 | |
| 44 | 44 | Main.navigateTo(window.location.hash); |
| 45 | 45 | |
| 46 | + $('.oauth-login').on('click touchstart', function(e) { | |
| 47 | + Main.oauthClientAction($(this).attr('href')); | |
| 48 | + e.preventDefault(); | |
| 49 | + }); | |
| 50 | + | |
| 46 | 51 | //Actions for links |
| 47 | 52 | $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ |
| 48 | 53 | e.preventDefault(); |
| ... | ... | @@ -515,6 +520,23 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 515 | 520 | }else{ |
| 516 | 521 | this.display_proposal_by_category('proposal-item-' + categoryId); |
| 517 | 522 | } |
| 523 | + }, | |
| 524 | + oauthClientAction: function(url) { | |
| 525 | + var child = window.open(url, "_blank"); | |
| 526 | + var interval = setInterval(function() { | |
| 527 | + try { | |
| 528 | + if(!child.closed) { | |
| 529 | + child.postMessage({ message: "requestOauthClientPluginResult" }, "*"); | |
| 530 | + } | |
| 531 | + } | |
| 532 | + catch(e) { | |
| 533 | + // we're here when the child window has been navigated away or closed | |
| 534 | + if (child.closed) { | |
| 535 | + clearInterval(interval); | |
| 536 | + return; | |
| 537 | + } | |
| 538 | + } | |
| 539 | + }, 300); | |
| 518 | 540 | } |
| 519 | 541 | } |
| 520 | 542 | })(); |
| ... | ... | @@ -550,9 +572,12 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ |
| 550 | 572 | }); |
| 551 | 573 | }); |
| 552 | 574 | |
| 553 | - window.oauthPluginHandleLoginResult = function(loggedIn, token) { | |
| 554 | - Main.loginCallback(loggedIn, token); | |
| 555 | - } | |
| 575 | + window.addEventListener("message", function(ev) { | |
| 576 | + if (ev.data.message === "oauthClientPluginResult") { | |
| 577 | + Main.loginCallback(ev.data.logged_in, ev.data.private_token); | |
| 578 | + ev.source.close(); | |
| 579 | + } | |
| 580 | + }); | |
| 556 | 581 | |
| 557 | 582 | if('onhashchange' in window){ |
| 558 | 583 | window.onhashchange = function(){ | ... | ... |