From 3883e76d6091d80549b5f91e2b88d9915d6ed1a4 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 30 Apr 2015 22:01:23 -0300 Subject: [PATCH] Refactoring oauth login --- index.html | 4 ++-- js/main.js | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 7a1338f..fb9d886 100644 --- a/index.html +++ b/index.html @@ -333,8 +333,8 @@
Acessar com:
- - Google + + + Cadastrar
diff --git a/js/main.js b/js/main.js index 615896b..5a6c95a 100644 --- a/js/main.js +++ b/js/main.js @@ -43,6 +43,11 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ Main.navigateTo(window.location.hash); + $('.oauth-login').on('click touchstart', function(e) { + Main.oauthClientAction($(this).attr('href')); + e.preventDefault(); + }); + //Actions for links $( '#nav-proposal-categories a' ).on('click touchstart', function(e){ e.preventDefault(); @@ -515,6 +520,23 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ }else{ this.display_proposal_by_category('proposal-item-' + categoryId); } + }, + oauthClientAction: function(url) { + var child = window.open(url, "_blank"); + var interval = setInterval(function() { + try { + if(!child.closed) { + child.postMessage({ message: "requestOauthClientPluginResult" }, "*"); + } + } + catch(e) { + // we're here when the child window has been navigated away or closed + if (child.closed) { + clearInterval(interval); + return; + } + } + }, 300); } } })(); @@ -550,9 +572,12 @@ define(['handlebars','handlebars_helpers'], function(Handlebars){ }); }); - window.oauthPluginHandleLoginResult = function(loggedIn, token) { - Main.loginCallback(loggedIn, token); - } + window.addEventListener("message", function(ev) { + if (ev.data.message === "oauthClientPluginResult") { + Main.loginCallback(ev.data.logged_in, ev.data.private_token); + ev.source.close(); + } + }); if('onhashchange' in window){ window.onhashchange = function(){ -- libgit2 0.21.2