From 3fcda8fc46b021c087264296b92d0fd9753b992b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 18 Feb 2016 18:05:26 +0100 Subject: [PATCH] MOBILE-1425 login: Fix modal shown when using fixed url with browser SSO --- .../login/controllers/credentials.js | 10 +++++-- www/core/components/login/main.js | 15 +++++----- www/core/components/login/services/helper.js | 29 ++++++++++++++++++- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/www/core/components/login/controllers/credentials.js b/www/core/components/login/controllers/credentials.js index f0e2554d336..e08b293fb99 100644 --- a/www/core/components/login/controllers/credentials.js +++ b/www/core/components/login/controllers/credentials.js @@ -48,9 +48,13 @@ angular.module('mm.core.login') if ($mmLoginHelper.isSSOLoginNeeded(result.code)) { // SSO. User needs to authenticate in a browser. $scope.isBrowserSSO = true; - $mmUtil.showConfirm($translate('mm.login.logininsiterequired')).then(function() { - $mmLoginHelper.openBrowserForSSOLogin(result.siteurl); - }); + + // Check that there's no SSO authentication ongoing and the view hasn't changed. + if (!$mmLoginHelper.isSSOLoginOngoing() && !$scope.$$destroyed) { + $mmUtil.showConfirm($translate('mm.login.logininsiterequired')).then(function() { + $mmLoginHelper.openBrowserForSSOLogin(result.siteurl); + }); + } } else { $scope.isBrowserSSO = false; } diff --git a/www/core/components/login/main.js b/www/core/components/login/main.js index 8adb9ec619b..1c316efc7ba 100644 --- a/www/core/components/login/main.js +++ b/www/core/components/login/main.js @@ -184,6 +184,7 @@ angular.module('mm.core.login', []) } // App opened using custom URL scheme. Probably an SSO authentication. + $mmLoginHelper.setSSOLoginOngoing(true); $log.debug('App launched by URL'); var modal = $mmUtil.showModalLoading('mm.login.authenticating', true); @@ -201,19 +202,17 @@ angular.module('mm.core.login', []) $mmLoginHelper.validateBrowserSSOLogin(url).then(function(sitedata) { - $mmLoginHelper.handleSSOLoginAuthentication(sitedata.siteurl, sitedata.token).then(function() { + return $mmLoginHelper.handleSSOLoginAuthentication(sitedata.siteurl, sitedata.token).then(function() { return $mmLoginHelper.goToSiteInitialPage(); - }, function(error) { - $mmUtil.showErrorModal(error); - }).finally(function() { - modal.dismiss(); }); - }, function(errorMessage) { - modal.dismiss(); - if (typeof(errorMessage) === 'string' && errorMessage != '') { + }).catch(function(errorMessage) { + if (typeof errorMessage === 'string' && errorMessage !== '') { $mmUtil.showErrorModal(errorMessage); } + }).finally(function() { + modal.dismiss(); + $mmLoginHelper.setSSOLoginOngoing(false); }); return true; diff --git a/www/core/components/login/services/helper.js b/www/core/components/login/services/helper.js index 1cd1c8ef826..c63e12bffe8 100644 --- a/www/core/components/login/services/helper.js +++ b/www/core/components/login/services/helper.js @@ -30,7 +30,8 @@ angular.module('mm.core.login') $log = $log.getInstance('$mmLoginHelper'); - var self = {}; + var self = {}, + isSSOLoginOngoing = false; /** * Go to the view to add a new site. @@ -95,6 +96,19 @@ angular.module('mm.core.login') return code == mmLoginSSOCode; }; + /** + * Check if there's an SSO authentication ongoing. This should be true if the app was opened by a browser because of + * a SSO login and the authentication hasn't finished yet. + * + * @module mm.core.login + * @ngdoc method + * @name $mmLoginHelper#isSSOLoginOngoing + * @return {Boolean} True if SSO is ongoing, false otherwise. + */ + self.isSSOLoginOngoing = function() { + return isSSOLoginOngoing; + }; + /** * Open a browser to perform SSO login. * @@ -119,6 +133,19 @@ angular.module('mm.core.login') } }; + /** + * Set the "SSO authentication ongoing" flag to true or false. + * + * @module mm.core.login + * @ngdoc method + * @name $mmLoginHelper#setSSOLoginOngoing + * @param {Boolean} value Value to set. + * @return {Void} + */ + self.setSSOLoginOngoing = function(value) { + isSSOLoginOngoing = value; + }; + /** * Convenient helper to validate a browser SSO login. *