From 1e03a201a40c4506711bc70ca24525be237e5a8f Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 19 May 2021 13:41:11 +0200 Subject: [PATCH 1/2] MOBILE-3716 login: Fix cancel in reconnect screen --- src/app/app.component.ts | 14 ++++++++++---- .../features/login/pages/reconnect/reconnect.ts | 3 +-- src/core/features/login/services/login-helper.ts | 10 +++++----- .../siteplugins/services/siteplugins-helper.ts | 8 -------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index d81f14598..b514da30c 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -28,6 +28,7 @@ import { CoreCustomURLSchemes } from '@services/urlschemes'; import { CoreUtils } from '@services/utils/utils'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreConstants } from '@/core/constants'; +import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; const MOODLE_VERSION_PREFIX = 'version-'; const MOODLEAPP_VERSION_PREFIX = 'moodleapp-'; @@ -61,15 +62,20 @@ export class AppComponent implements OnInit, AfterViewInit { document.body.classList.add('ionic5'); this.addVersionClass(MOODLEAPP_VERSION_PREFIX, CoreConstants.CONFIG.versionname.replace('-dev', '')); - CoreEvents.on(CoreEvents.LOGOUT, () => { - // Go to sites page when user is logged out. - CoreNavigator.navigate('/login/sites', { reset: true }); - + CoreEvents.on(CoreEvents.LOGOUT, async () => { // Unload lang custom strings. CoreLang.clearCustomStrings(); // Remove version classes from body. this.removeVersionClass(MOODLE_VERSION_PREFIX); + + // Go to sites page when user is logged out. + await CoreNavigator.navigate('/login/sites', { reset: true }); + + if (CoreSitePlugins.hasSitePluginsLoaded) { + // Temporary fix. Reload the page to unload all plugins. + window.location.reload(); + } }); // Listen for session expired events. diff --git a/src/core/features/login/pages/reconnect/reconnect.ts b/src/core/features/login/pages/reconnect/reconnect.ts index 21c3c4f9a..850f8f050 100644 --- a/src/core/features/login/pages/reconnect/reconnect.ts +++ b/src/core/features/login/pages/reconnect/reconnect.ts @@ -62,7 +62,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { constructor( protected fb: FormBuilder, ) { - const currentSite = CoreSites.getCurrentSite(); this.isLoggedOut = !!currentSite?.isLoggedOut(); @@ -80,7 +79,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { return this.cancel(); } - this.siteUrl = siteId; + this.siteId = siteId; this.page = CoreNavigator.getRouteParam('pageName'); this.pageOptions = CoreNavigator.getRouteParam('pageOptions'); this.showScanQR = CoreLoginHelper.displayQRInSiteScreen() || CoreLoginHelper.displayQRInCredentialsScreen(); diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index 8d24d8c98..261d6ac7b 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -903,12 +903,12 @@ export class CoreLoginHelperProvider { if (!CoreApp.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) { this.isSSOConfirmShown = true; - if (this.shouldShowSSOConfirm(result.code)) { - await CoreDomUtils.showConfirm(Translate.instant('core.login.' + - (currentSite.isLoggedOut() ? 'loggedoutssodescription' : 'reconnectssodescription'))); - } - try { + if (this.shouldShowSSOConfirm(result.code)) { + await CoreDomUtils.showConfirm(Translate.instant('core.login.' + + (currentSite.isLoggedOut() ? 'loggedoutssodescription' : 'reconnectssodescription'))); + } + this.waitingForBrowser = true; this.openBrowserForSSOLogin( diff --git a/src/core/features/siteplugins/services/siteplugins-helper.ts b/src/core/features/siteplugins/services/siteplugins-helper.ts index 9acacb577..84a1b626b 100644 --- a/src/core/features/siteplugins/services/siteplugins-helper.ts +++ b/src/core/features/siteplugins/services/siteplugins-helper.ts @@ -135,14 +135,6 @@ export class CoreSitePluginsHelperProvider { } }); - // Unload plugins on logout if any. - CoreEvents.on(CoreEvents.LOGOUT, () => { - if (CoreSitePlugins.hasSitePluginsLoaded) { - // Temporary fix. Reload the page to unload all plugins. - window.location.reload(); - } - }); - // Re-load plugins restricted for courses when the list of user courses changes. CoreEvents.on(CoreCoursesProvider.EVENT_MY_COURSES_CHANGED, (data) => { if (data && data.siteId && data.siteId == CoreSites.getCurrentSiteId() && data.added && data.added.length) { From 2159be957d77f56042320eb3900643a80c05536e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 19 May 2021 15:46:21 +0200 Subject: [PATCH 2/2] MOBILE-3716 core: Fix token error for logged out sites --- src/core/classes/site.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index 1511a3ac2..a8a70f875 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -146,7 +146,7 @@ export class CoreSite { * @return Site ID. */ getId(): string { - if (!this.id) { + if (this.id === undefined) { // Shouldn't happen for authenticated sites. throw new CoreError('This site doesn\'t have an ID'); } @@ -169,7 +169,7 @@ export class CoreSite { * @return Site token. */ getToken(): string { - if (!this.token) { + if (this.token === undefined) { // Shouldn't happen for authenticated sites. throw new CoreError('This site doesn\'t have a token'); }