From aca09a2dc2304384174d100449fdbd055d2eceab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 1 Aug 2019 10:04:32 +0200 Subject: [PATCH] MOBILE-3081 login: Show download button on version check --- src/core/login/pages/credentials/credentials.ts | 3 +++ src/core/login/pages/init/init.ts | 10 ++-------- src/core/login/pages/reconnect/reconnect.ts | 15 +++++++++++++-- src/core/login/pages/site/site.ts | 8 +++++++- src/core/login/pages/sites/sites.ts | 4 ++++ src/providers/sites.ts | 3 ++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/core/login/pages/credentials/credentials.ts b/src/core/login/pages/credentials/credentials.ts index 3c2089190..eb791bab4 100644 --- a/src/core/login/pages/credentials/credentials.ts +++ b/src/core/login/pages/credentials/credentials.ts @@ -220,6 +220,9 @@ export class CoreLoginCredentialsPage { }); }).catch((error) => { this.loginHelper.treatUserTokenError(siteUrl, error, username, password); + if (error.loggedout) { + this.navCtrl.setRoot('CoreLoginSitesPage'); + } }).finally(() => { modal.dismiss(); }); diff --git a/src/core/login/pages/init/init.ts b/src/core/login/pages/init/init.ts index a33c0b2d5..3cadcccfb 100644 --- a/src/core/login/pages/init/init.ts +++ b/src/core/login/pages/init/init.ts @@ -94,14 +94,8 @@ export class CoreLoginInitPage { return this.loadPage(); }); } - } else { - return this.sitesProvider.hasSites().then((hasSites) => { - if (hasSites) { - return this.navCtrl.setRoot('CoreLoginSitesPage'); - } else { - return this.loginHelper.goToAddSite(true); - } - }); } + + return this.navCtrl.setRoot('CoreLoginSitesPage'); } } diff --git a/src/core/login/pages/reconnect/reconnect.ts b/src/core/login/pages/reconnect/reconnect.ts index b7882e1f1..ba08c11be 100644 --- a/src/core/login/pages/reconnect/reconnect.ts +++ b/src/core/login/pages/reconnect/reconnect.ts @@ -103,7 +103,9 @@ export class CoreLoginReconnectPage { * Cancel reconnect. */ cancel(): void { - this.sitesProvider.logout().finally(() => { + this.sitesProvider.logout().catch(() => { + // Ignore errors (shouldn't happen). + }).finally(() => { this.navCtrl.setRoot('CoreLoginSitesPage'); }); } @@ -149,13 +151,22 @@ export class CoreLoginReconnectPage { // Go to the site initial page. return this.loginHelper.goToSiteInitialPage(this.navCtrl, this.pageName, this.pageParams); }).catch((error) => { + if (error.loggedout) { + this.loginHelper.treatUserTokenError(siteUrl, error, username, password); + } else { + this.domUtils.showErrorModalDefault(error, 'core.login.errorupdatesite', true); + } + // Error, go back to login page. - this.domUtils.showErrorModalDefault(error, 'core.login.errorupdatesite', true); this.cancel(); }); }); }).catch((error) => { this.loginHelper.treatUserTokenError(siteUrl, error, username, password); + + if (error.loggedout) { + this.cancel(); + } }).finally(() => { modal.dismiss(); }); diff --git a/src/core/login/pages/site/site.ts b/src/core/login/pages/site/site.ts index 8b1fcf600..856797acd 100644 --- a/src/core/login/pages/site/site.ts +++ b/src/core/login/pages/site/site.ts @@ -95,10 +95,16 @@ export class CoreLoginSitePage { return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken).then(() => { return this.loginHelper.goToSiteInitialPage(); }, (error) => { - this.domUtils.showErrorModal(error); + this.loginHelper.treatUserTokenError(siteData.url, error, siteData.username, siteData.password); + if (error.loggedout) { + this.navCtrl.setRoot('CoreLoginSitesPage'); + } }); }, (error) => { this.loginHelper.treatUserTokenError(siteData.url, error, siteData.username, siteData.password); + if (error.loggedout) { + this.navCtrl.setRoot('CoreLoginSitesPage'); + } }).finally(() => { modal.dismiss(); }); diff --git a/src/core/login/pages/sites/sites.ts b/src/core/login/pages/sites/sites.ts index 5f6c8a8c0..2fcbc96ab 100644 --- a/src/core/login/pages/sites/sites.ts +++ b/src/core/login/pages/sites/sites.ts @@ -46,6 +46,10 @@ export class CoreLoginSitesPage { */ ionViewDidLoad(): void { this.sitesProvider.getSortedSites().then((sites) => { + if (sites.length == 0) { + this.loginHelper.goToAddSite(true); + } + // Remove protocol from the url to show more url text. this.sites = sites.map((site) => { site.siteUrl = site.siteUrl.replace(/^https?:\/\//, ''); diff --git a/src/providers/sites.ts b/src/providers/sites.ts index 09e3fcb85..a80aca762 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -715,7 +715,8 @@ export class CoreSitesProvider { return promise.then(() => { return Promise.reject({ error: this.translate.instant(errorKey, errorKeyParams) + errorExtra, - errorcode: errorCode + errorcode: errorCode, + loggedout: true }); }); }