diff --git a/src/core/login/lang/en.json b/src/core/login/lang/en.json
index c9031b28d..66b50a90d 100644
--- a/src/core/login/lang/en.json
+++ b/src/core/login/lang/en.json
@@ -33,6 +33,7 @@
"invalidvaluemax": "The maximum value is {{$a}}",
"invalidvaluemin": "The minimum value is {{$a}}",
"legacymoodleversion": "You are trying to connect to an unsupported Moodle version. Please, download the Moodle Classic app to access this Moodle site.",
+ "legacymoodleversiondesktop": "You are trying to connect to {{$a}}.
This site is running an outdated unsupported version of Moodle which will not work with this Moodle Desktop App.
If this is your site please contact your local moodle partner to get assistance to update it.
See our contact page to submit a request for assistance.",
"localmobileunexpectedresponse": "Moodle Mobile Additional Features check returned an unexpected response, you will be authenticated using the standard Mobile service.",
"login": "Log in",
"loginbutton": "Log in",
diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts
index 35be01e17..a690bb6ec 100644
--- a/src/core/login/providers/helper.ts
+++ b/src/core/login/providers/helper.ts
@@ -14,7 +14,7 @@
import { Injectable } from '@angular/core';
import { Location } from '@angular/common';
-import { Platform } from 'ionic-angular';
+import { Platform, AlertController } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app';
import { CoreConfigProvider } from '@providers/config';
@@ -83,7 +83,7 @@ export class CoreLoginHelperProvider {
private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider,
private urlUtils: CoreUrlUtilsProvider, private configProvider: CoreConfigProvider, private platform: Platform,
private initDelegate: CoreInitDelegate, private sitePluginsProvider: CoreSitePluginsProvider,
- private location: Location) {
+ private location: Location, private alertCtrl: AlertController) {
this.logger = logger.getInstance('CoreLoginHelper');
}
@@ -924,6 +924,47 @@ export class CoreLoginHelperProvider {
(!CoreConfigConstants.skipssoconfirmation || String(CoreConfigConstants.skipssoconfirmation) === 'false');
}
+ /**
+ * Show a modal warning the user that he should use the Classic app.
+ *
+ * @param {string} message The warning message.
+ */
+ protected showLegacyNoticeModal(message: string): void {
+ const isAndroid = this.platform.is('android'),
+ isIOS = this.platform.is('ios'),
+ buttons: any[] = [
+ {
+ text: this.translate.instant('core.ok'),
+ role: 'cancel'
+ }
+ ];
+
+ if (isAndroid || isIOS) {
+ buttons.push({
+ text: this.translate.instant('core.download'),
+ handler: (): void => {
+ const link = isAndroid ? 'market://details?id=com.moodle.classic' :
+ 'itms-apps://itunes.apple.com/app/id1403448117';
+
+ this.utils.openInBrowser(link);
+ }
+ });
+ }
+
+ const alert = this.alertCtrl.create({
+ message: message,
+ buttons: buttons
+ });
+
+ alert.present().then(() => {
+ if (!isAndroid && !isIOS) {
+ // Treat all anchors so they don't override the app.
+ const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
+ this.domUtils.treatAnchors(alertMessageEl);
+ }
+ });
+ }
+
/**
* Function called when site policy is not agreed. Reserved for core use.
*
@@ -961,6 +1002,8 @@ export class CoreLoginHelperProvider {
treatUserTokenError(siteUrl: string, error: any): void {
if (error.errorcode == 'forcepasswordchangenotice') {
this.openChangePassword(siteUrl, error.error || error.message || error.body || error.content);
+ } else if (error.errorcode == 'legacymoodleversion') {
+ this.showLegacyNoticeModal(error.error);
} else {
this.domUtils.showErrorModal(error);
}
diff --git a/src/providers/sites.ts b/src/providers/sites.ts
index c3e8678bb..11825e259 100644
--- a/src/providers/sites.ts
+++ b/src/providers/sites.ts
@@ -494,9 +494,23 @@ export class CoreSitesProvider {
return siteId;
});
} else if (result == this.LEGACY_APP_VERSION) {
- return Promise.reject(this.translate.instant('core.login.legacymoodleversion'));
+ let errorKey = 'core.login.legacymoodleversion',
+ params;
+
+ if (this.appProvider.isDesktop()) {
+ errorKey += 'desktop';
+ params = {$a: siteUrl};
+ }
+
+ return Promise.reject({
+ error: this.translate.instant(errorKey, params),
+ errorcode: 'legacymoodleversion'
+ });
} else {
- return Promise.reject(this.translate.instant('core.login.invalidmoodleversion'));
+ return Promise.reject({
+ error: this.translate.instant('core.login.invalidmoodleversion'),
+ errorcode: 'invalidmoodleversion'
+ });
}
});
}
diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts
index d8ebbe017..361fabcd9 100644
--- a/src/providers/utils/dom.ts
+++ b/src/providers/utils/dom.ts
@@ -1205,7 +1205,7 @@ export class CoreDomUtilsProvider {
*
* @param {HTMLElement} container The HTMLElement that can contain anchors.
*/
- protected treatAnchors(container: HTMLElement): void {
+ treatAnchors(container: HTMLElement): void {
const anchors = Array.from(container.querySelectorAll('a'));
anchors.forEach((anchor) => {