From a16c3d3ce6bf8c5dce2af0b6aa2a4a4521db3ab3 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 5 May 2021 17:52:40 +0200 Subject: [PATCH] MOBILE-3320 login: Fix application check --- src/core/features/login/pages/site/site.ts | 48 ++++++++++++---------- src/core/services/sites.ts | 33 ++++++++------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index 0bbdc4939..7eb62e9c8 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -348,32 +348,36 @@ export class CoreLoginSitePage implements OnInit { * @return Promise resolved after logging in. */ protected async login(response: CoreSiteCheckResponse, foundSite?: CoreLoginSiteInfoExtended): Promise { - await CoreUtils.ignoreErrors(CoreSites.checkApplication(response)); + try { + await CoreSites.checkApplication(response); - CoreForms.triggerFormSubmittedEvent(this.formElement, true); + CoreForms.triggerFormSubmittedEvent(this.formElement, true); - if (response.warning) { - CoreDomUtils.showErrorModal(response.warning, true, 4000); - } - - if (CoreLoginHelper.isSSOLoginNeeded(response.code)) { - // SSO. User needs to authenticate in a browser. - CoreLoginHelper.confirmAndOpenBrowserForSSOLogin( - response.siteUrl, - response.code, - response.service, - response.config?.launchurl, - ); - } else { - const pageParams = { siteUrl: response.siteUrl, siteConfig: response.config }; - if (foundSite && !this.fixedSites) { - pageParams['siteName'] = foundSite.name; - pageParams['logoUrl'] = foundSite.imageurl; + if (response.warning) { + CoreDomUtils.showErrorModal(response.warning, true, 4000); } - CoreNavigator.navigate('/login/credentials', { - params: pageParams, - }); + if (CoreLoginHelper.isSSOLoginNeeded(response.code)) { + // SSO. User needs to authenticate in a browser. + CoreLoginHelper.confirmAndOpenBrowserForSSOLogin( + response.siteUrl, + response.code, + response.service, + response.config?.launchurl, + ); + } else { + const pageParams = { siteUrl: response.siteUrl, siteConfig: response.config }; + if (foundSite && !this.fixedSites) { + pageParams['siteName'] = foundSite.name; + pageParams['logoUrl'] = foundSite.imageurl; + } + + CoreNavigator.navigate('/login/credentials', { + params: pageParams, + }); + } + } catch (error) { + // Ignore errors. } } diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index b85663783..a022d4783 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -1174,28 +1174,27 @@ export class CoreSitesProvider { * @return Promise resolved when the user is logged out. */ async logout(): Promise { - let siteId: string | undefined; + if (!this.currentSite) { + return; + } + + const db = await this.appDB; + const promises: Promise[] = []; + const siteConfig = this.currentSite.getStoredConfig(); + const siteId = this.currentSite.getId(); - if (this.currentSite) { - const db = await this.appDB; - const siteConfig = this.currentSite.getStoredConfig(); - siteId = this.currentSite.getId(); + this.currentSite = undefined; - this.currentSite = undefined; - - if (siteConfig && siteConfig.tool_mobile_forcelogout == '1') { - promises.push(this.setSiteLoggedOut(siteId, true)); - } - - promises.push(db.deleteRecords(CURRENT_SITE_TABLE_NAME, { id: 1 })); + if (siteConfig && siteConfig.tool_mobile_forcelogout == '1') { + promises.push(this.setSiteLoggedOut(siteId, true)); } - try { - await Promise.all(promises); - } finally { - CoreEvents.trigger(CoreEvents.LOGOUT, {}, siteId); - } + promises.push(db.deleteRecords(CURRENT_SITE_TABLE_NAME, { id: 1 })); + + await CoreUtils.ignoreErrors(Promise.all(promises)); + + CoreEvents.trigger(CoreEvents.LOGOUT, {}, siteId); } /**