Skip to content

Commit 3fcda8f

Browse files
committed
MOBILE-1425 login: Fix modal shown when using fixed url with browser SSO
1 parent 771d2a2 commit 3fcda8f

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

www/core/components/login/controllers/credentials.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ angular.module('mm.core.login')
4848
if ($mmLoginHelper.isSSOLoginNeeded(result.code)) {
4949
// SSO. User needs to authenticate in a browser.
5050
$scope.isBrowserSSO = true;
51-
$mmUtil.showConfirm($translate('mm.login.logininsiterequired')).then(function() {
52-
$mmLoginHelper.openBrowserForSSOLogin(result.siteurl);
53-
});
51+
52+
// Check that there's no SSO authentication ongoing and the view hasn't changed.
53+
if (!$mmLoginHelper.isSSOLoginOngoing() && !$scope.$$destroyed) {
54+
$mmUtil.showConfirm($translate('mm.login.logininsiterequired')).then(function() {
55+
$mmLoginHelper.openBrowserForSSOLogin(result.siteurl);
56+
});
57+
}
5458
} else {
5559
$scope.isBrowserSSO = false;
5660
}

www/core/components/login/main.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ angular.module('mm.core.login', [])
184184
}
185185

186186
// App opened using custom URL scheme. Probably an SSO authentication.
187+
$mmLoginHelper.setSSOLoginOngoing(true);
187188
$log.debug('App launched by URL');
188189

189190
var modal = $mmUtil.showModalLoading('mm.login.authenticating', true);
@@ -201,19 +202,17 @@ angular.module('mm.core.login', [])
201202

202203
$mmLoginHelper.validateBrowserSSOLogin(url).then(function(sitedata) {
203204

204-
$mmLoginHelper.handleSSOLoginAuthentication(sitedata.siteurl, sitedata.token).then(function() {
205+
return $mmLoginHelper.handleSSOLoginAuthentication(sitedata.siteurl, sitedata.token).then(function() {
205206
return $mmLoginHelper.goToSiteInitialPage();
206-
}, function(error) {
207-
$mmUtil.showErrorModal(error);
208-
}).finally(function() {
209-
modal.dismiss();
210207
});
211208

212-
}, function(errorMessage) {
213-
modal.dismiss();
214-
if (typeof(errorMessage) === 'string' && errorMessage != '') {
209+
}).catch(function(errorMessage) {
210+
if (typeof errorMessage === 'string' && errorMessage !== '') {
215211
$mmUtil.showErrorModal(errorMessage);
216212
}
213+
}).finally(function() {
214+
modal.dismiss();
215+
$mmLoginHelper.setSSOLoginOngoing(false);
217216
});
218217

219218
return true;

www/core/components/login/services/helper.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ angular.module('mm.core.login')
3030

3131
$log = $log.getInstance('$mmLoginHelper');
3232

33-
var self = {};
33+
var self = {},
34+
isSSOLoginOngoing = false;
3435

3536
/**
3637
* Go to the view to add a new site.
@@ -95,6 +96,19 @@ angular.module('mm.core.login')
9596
return code == mmLoginSSOCode;
9697
};
9798

99+
/**
100+
* Check if there's an SSO authentication ongoing. This should be true if the app was opened by a browser because of
101+
* a SSO login and the authentication hasn't finished yet.
102+
*
103+
* @module mm.core.login
104+
* @ngdoc method
105+
* @name $mmLoginHelper#isSSOLoginOngoing
106+
* @return {Boolean} True if SSO is ongoing, false otherwise.
107+
*/
108+
self.isSSOLoginOngoing = function() {
109+
return isSSOLoginOngoing;
110+
};
111+
98112
/**
99113
* Open a browser to perform SSO login.
100114
*
@@ -119,6 +133,19 @@ angular.module('mm.core.login')
119133
}
120134
};
121135

136+
/**
137+
* Set the "SSO authentication ongoing" flag to true or false.
138+
*
139+
* @module mm.core.login
140+
* @ngdoc method
141+
* @name $mmLoginHelper#setSSOLoginOngoing
142+
* @param {Boolean} value Value to set.
143+
* @return {Void}
144+
*/
145+
self.setSSOLoginOngoing = function(value) {
146+
isSSOLoginOngoing = value;
147+
};
148+
122149
/**
123150
* Convenient helper to validate a browser SSO login.
124151
*

0 commit comments

Comments
 (0)