MOBILE-2434 login: Handle old Moodle sites
parent
f6b2800472
commit
ec6ab104e6
|
@ -32,6 +32,7 @@
|
||||||
"invalidurl": "Invalid URL specified",
|
"invalidurl": "Invalid URL specified",
|
||||||
"invalidvaluemax": "The maximum value is {{$a}}",
|
"invalidvaluemax": "The maximum value is {{$a}}",
|
||||||
"invalidvaluemin": "The minimum 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.",
|
||||||
"localmobileunexpectedresponse": "Moodle Mobile Additional Features check returned an unexpected response, you will be authenticated using the standard Mobile service.",
|
"localmobileunexpectedresponse": "Moodle Mobile Additional Features check returned an unexpected response, you will be authenticated using the standard Mobile service.",
|
||||||
"login": "Log in",
|
"login": "Log in",
|
||||||
"loginbutton": "Log in",
|
"loginbutton": "Log in",
|
||||||
|
|
|
@ -137,7 +137,7 @@ export class CoreLoginReconnectPage {
|
||||||
this.sitesProvider.getUserToken(siteUrl, username, password).then((data) => {
|
this.sitesProvider.getUserToken(siteUrl, username, password).then((data) => {
|
||||||
return this.sitesProvider.updateSiteToken(this.infoSiteUrl, username, data.token, data.privateToken).then(() => {
|
return this.sitesProvider.updateSiteToken(this.infoSiteUrl, username, data.token, data.privateToken).then(() => {
|
||||||
// Update site info too because functions might have changed (e.g. unisntall local_mobile).
|
// Update site info too because functions might have changed (e.g. unisntall local_mobile).
|
||||||
return this.sitesProvider.updateSiteInfoByUrl(this.infoSiteUrl, username).finally(() => {
|
return this.sitesProvider.updateSiteInfoByUrl(this.infoSiteUrl, username).then(() => {
|
||||||
// Reset fields so the data is not in the view anymore.
|
// Reset fields so the data is not in the view anymore.
|
||||||
this.credForm.controls['password'].reset();
|
this.credForm.controls['password'].reset();
|
||||||
|
|
||||||
|
@ -148,8 +148,8 @@ export class CoreLoginReconnectPage {
|
||||||
return this.loginHelper.goToSiteInitialPage();
|
return this.loginHelper.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
// Site deleted? Go back to login page.
|
// Error, go back to login page.
|
||||||
this.domUtils.showErrorModal('core.login.errorupdatesite', true);
|
this.domUtils.showErrorModalDefault(error, 'core.login.errorupdatesite', true);
|
||||||
this.cancel();
|
this.cancel();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -178,8 +178,10 @@ export class CoreLoginHelperProvider {
|
||||||
this.goToSiteInitialPage();
|
this.goToSiteInitialPage();
|
||||||
}
|
}
|
||||||
}).catch((errorMessage) => {
|
}).catch((errorMessage) => {
|
||||||
if (typeof errorMessage == 'string' && errorMessage != '') {
|
if (errorMessage) {
|
||||||
|
// An error occurred, display the error and logout the user.
|
||||||
this.domUtils.showErrorModal(errorMessage);
|
this.domUtils.showErrorModal(errorMessage);
|
||||||
|
this.sitesProvider.logout();
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
modal.dismiss();
|
modal.dismiss();
|
||||||
|
@ -436,8 +438,8 @@ export class CoreLoginHelperProvider {
|
||||||
const info = this.sitesProvider.getCurrentSite().getInfo();
|
const info = this.sitesProvider.getCurrentSite().getInfo();
|
||||||
if (typeof info != 'undefined' && typeof info.username != 'undefined') {
|
if (typeof info != 'undefined' && typeof info.username != 'undefined') {
|
||||||
return this.sitesProvider.updateSiteToken(info.siteurl, info.username, token, privateToken).then(() => {
|
return this.sitesProvider.updateSiteToken(info.siteurl, info.username, token, privateToken).then(() => {
|
||||||
this.sitesProvider.updateSiteInfoByUrl(info.siteurl, info.username);
|
return this.sitesProvider.updateSiteInfoByUrl(info.siteurl, info.username);
|
||||||
}).catch(() => {
|
}, () => {
|
||||||
// Error updating token, return proper error message.
|
// Error updating token, return proper error message.
|
||||||
return Promise.reject(this.translate.instant('core.login.errorupdatesite'));
|
return Promise.reject(this.translate.instant('core.login.errorupdatesite'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1050,6 +1050,11 @@ export class CoreSitesProvider {
|
||||||
return site.fetchSiteInfo().then((info) => {
|
return site.fetchSiteInfo().then((info) => {
|
||||||
site.setInfo(info);
|
site.setInfo(info);
|
||||||
|
|
||||||
|
if (this.isLegacyMoodleByInfo(info)) {
|
||||||
|
// The Moodle version is not supported, reject.
|
||||||
|
return Promise.reject(this.translate.instant('core.login.legacymoodleversion'));
|
||||||
|
}
|
||||||
|
|
||||||
// Try to get the site config.
|
// Try to get the site config.
|
||||||
return this.getSiteConfig(site).catch(() => {
|
return this.getSiteConfig(site).catch(() => {
|
||||||
// Error getting config, keep the current one.
|
// Error getting config, keep the current one.
|
||||||
|
@ -1227,4 +1232,14 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
return site && site.wsAvailable(method, checkPrefix);
|
return site && site.wsAvailable(method, checkPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a site is a legacy site by its info.
|
||||||
|
*
|
||||||
|
* @param {any} info The site info.
|
||||||
|
* @return {boolean} Whether it's a legacy Moodle.
|
||||||
|
*/
|
||||||
|
isLegacyMoodleByInfo(info: any): boolean {
|
||||||
|
return this.isValidMoodleVersion(info) == this.LEGACY_APP_VERSION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,6 +367,10 @@ export class CoreUpdateManagerProvider implements CoreInitHandler {
|
||||||
// In version 2018 we adapted the forum offline stores to match a new schema.
|
// In version 2018 we adapted the forum offline stores to match a new schema.
|
||||||
// However, due to the migration of data to SQLite we can no longer do that.
|
// However, due to the migration of data to SQLite we can no longer do that.
|
||||||
|
|
||||||
|
if (versionCode >= 3500 && versionApplied < 3500 && versionApplied > 0) {
|
||||||
|
promises.push(this.logoutLegacySites());
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
return Promise.all(promises).then(() => {
|
||||||
return this.configProvider.set(this.VERSION_APPLIED, versionCode);
|
return this.configProvider.set(this.VERSION_APPLIED, versionCode);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
@ -684,4 +688,26 @@ export class CoreUpdateManagerProvider implements CoreInitHandler {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logout from legacy sites.
|
||||||
|
*
|
||||||
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected logoutLegacySites(): Promise<any> {
|
||||||
|
return this.sitesProvider.getSitesIds().then((siteIds) => {
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
|
siteIds.forEach((siteId) => {
|
||||||
|
promises.push(this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
|
// If the site is a legacy site, mark it as logged out so the user has to authenticate again.
|
||||||
|
if (this.sitesProvider.isLegacyMoodleByInfo(site.getInfo())) {
|
||||||
|
return this.sitesProvider.setSiteLoggedOut(site.getId(), true);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.utils.allPromises(promises);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue