Commit 3883e76d6091d80549b5f91e2b88d9915d6ed1a4

Authored by Victor Costa
1 parent 4c7f555f

Refactoring oauth login

Showing 2 changed files with 30 additions and 5 deletions   Show diff stats
@@ -333,8 +333,8 @@ @@ -333,8 +333,8 @@
333 </div> 333 </div>
334 <div class="oauth"> 334 <div class="oauth">
335 <div class="label">Acessar com:</div> 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 <a href="http://www.participa.br/account/signup" target="_blank" class="new-user">Cadastrar</a> 338 <a href="http://www.participa.br/account/signup" target="_blank" class="new-user">Cadastrar</a>
339 </div> 339 </div>
340 </form> 340 </form>
@@ -43,6 +43,11 @@ define([&#39;handlebars&#39;,&#39;handlebars_helpers&#39;], function(Handlebars){ @@ -43,6 +43,11 @@ define([&#39;handlebars&#39;,&#39;handlebars_helpers&#39;], function(Handlebars){
43 43
44 Main.navigateTo(window.location.hash); 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 //Actions for links 51 //Actions for links
47 $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ 52 $( '#nav-proposal-categories a' ).on('click touchstart', function(e){
48 e.preventDefault(); 53 e.preventDefault();
@@ -515,6 +520,23 @@ define([&#39;handlebars&#39;,&#39;handlebars_helpers&#39;], function(Handlebars){ @@ -515,6 +520,23 @@ define([&#39;handlebars&#39;,&#39;handlebars_helpers&#39;], function(Handlebars){
515 }else{ 520 }else{
516 this.display_proposal_by_category('proposal-item-' + categoryId); 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([&#39;handlebars&#39;,&#39;handlebars_helpers&#39;], function(Handlebars){ @@ -550,9 +572,12 @@ define([&#39;handlebars&#39;,&#39;handlebars_helpers&#39;], 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 if('onhashchange' in window){ 582 if('onhashchange' in window){
558 window.onhashchange = function(){ 583 window.onhashchange = function(){