Merge pull request #1676 from dpalou/MOBILE-2794

MOBILE-2794 login: Don't trigger login event if logged out
main
Juan Leyva 2018-12-18 16:48:27 +01:00 committed by GitHub
commit 0297c0fe25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 12 deletions

View File

@ -51,8 +51,10 @@ export class CoreLoginInitPage {
if (Date.now() - redirectData.timemodified < 20000) {
if (redirectData.siteId != CoreConstants.NO_SITE_ID) {
// The redirect is pointing to a site, load it.
return this.sitesProvider.loadSite(redirectData.siteId).then(() => {
if (!this.loginHelper.isSiteLoggedOut(redirectData.page, redirectData.params)) {
return this.sitesProvider.loadSite(redirectData.siteId, redirectData.page, redirectData.params)
.then((loggedIn) => {
if (loggedIn) {
return this.navCtrl.setRoot(redirectData.page, redirectData.params, { animate: false });
}
}).catch(() => {

View File

@ -113,8 +113,8 @@ export class CoreLoginSitesPage {
login(siteId: string): void {
const modal = this.domUtils.showModalLoading();
this.sitesProvider.loadSite(siteId).then(() => {
if (!this.loginHelper.isSiteLoggedOut()) {
this.sitesProvider.loadSite(siteId).then((loggedIn) => {
if (loggedIn) {
return this.loginHelper.goToSiteInitialPage();
}
}).catch((error) => {

View File

@ -591,8 +591,8 @@ export class CoreLoginHelperProvider {
this.appProvider.getRootNavController().setRoot(page, params);
} else {
const modal = this.domUtils.showModalLoading();
this.sitesProvider.loadSite(siteId).then(() => {
if (!this.isSiteLoggedOut(page, params)) {
this.sitesProvider.loadSite(siteId, page, params).then((loggedIn) => {
if (loggedIn) {
this.loadPageInMainMenu(page, params);
}
}).catch(() => {

View File

@ -665,27 +665,42 @@ export class CoreSitesProvider {
* Login a user to a site from the list of sites.
*
* @param {string} siteId ID of the site to load.
* @return {Promise} Promise to be resolved when the site is loaded.
* @param {string} [pageName] Name of the page to go once authenticated if logged out. If not defined, site initial page.
* @param {any} [params] Params of the page to go once authenticated if logged out.
* @return {Promise<boolean>} Promise resolved with true if site is loaded, resolved with false if cannot login.
*/
loadSite(siteId: string): Promise<any> {
loadSite(siteId: string, pageName?: string, params?: any): Promise<boolean> {
this.logger.debug(`Load site ${siteId}`);
return this.getSite(siteId).then((site) => {
this.currentSite = site;
this.login(siteId);
if (site.isLoggedOut()) {
// Logged out, nothing else to do.
return;
// Logged out, trigger session expired event and stop.
this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {
pageName: pageName,
params: params
}, site.getId());
return false;
}
// Check if local_mobile was installed to Moodle.
return site.checkIfLocalMobileInstalledAndNotUsed().then(() => {
// Local mobile was added. Throw invalid session to force reconnect and create a new token.
this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {}, siteId);
this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {
pageName: pageName,
params: params
}, siteId);
return false;
}, () => {
this.login(siteId);
// Update site info. We don't block the UI.
this.updateSiteInfo(siteId);
return true;
});
});
}

View File

@ -7,6 +7,7 @@ information provided here is intended especially for developers.
It's also recommended to update ionic cli to v4, otherwise some errors could be raised while building: npm install -g ionic
- The value of the constant CoreCourseProvider.ALL_SECTIONS_ID has changed from -1 to -2.
- Use of completionstatus on the module object has been deprecated, use completiondata instead.
- The function CoreSitesProvider.loadSite has changed, now it will trigger SESSION_EXPIRED event if the site is logged out. Its params and return value have changed.
- The following strings have been deprecated:
core.dfdaymonthyear. Please use core.strftimedatefullshort instead.
core.dfdayweekmonth. Please use core.strftimedayshort instead.