commit
						d165b06a07
					
				@ -80,10 +80,16 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
 | 
				
			|||||||
    protected urlToOpen?: string;
 | 
					    protected urlToOpen?: string;
 | 
				
			||||||
    protected valueChangeSubscription?: Subscription;
 | 
					    protected valueChangeSubscription?: Subscription;
 | 
				
			||||||
    protected alwaysShowLoginFormObserver?: CoreEventObserver;
 | 
					    protected alwaysShowLoginFormObserver?: CoreEventObserver;
 | 
				
			||||||
 | 
					    protected loginObserver?: CoreEventObserver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
        protected fb: FormBuilder,
 | 
					        protected fb: FormBuilder,
 | 
				
			||||||
    ) {}
 | 
					    ) {
 | 
				
			||||||
 | 
					        // Listen to LOGIN event to determine if login was successful, since the login can be done using QR, SSO, etc.
 | 
				
			||||||
 | 
					        this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, ({ siteId }) => {
 | 
				
			||||||
 | 
					            this.siteId = siteId;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @inheritdoc
 | 
					     * @inheritdoc
 | 
				
			||||||
@ -297,14 +303,12 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            const data = await CoreSites.getUserToken(siteUrl, username, password);
 | 
					            const data = await CoreSites.getUserToken(siteUrl, username, password);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const id = await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
 | 
					            await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // 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['username'].reset();
 | 
					            this.credForm.controls['username'].reset();
 | 
				
			||||||
            this.credForm.controls['password'].reset();
 | 
					            this.credForm.controls['password'].reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.siteId = id;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await CoreNavigator.navigateToSiteHome({ params: { urlToOpen: this.urlToOpen } });
 | 
					            await CoreNavigator.navigateToSiteHome({ params: { urlToOpen: this.urlToOpen } });
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            if (error instanceof CoreSiteError && CoreLoginHelper.isAppUnsupportedError(error)) {
 | 
					            if (error instanceof CoreSiteError && CoreLoginHelper.isAppUnsupportedError(error)) {
 | 
				
			||||||
@ -379,6 +383,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
        this.valueChangeSubscription?.unsubscribe();
 | 
					        this.valueChangeSubscription?.unsubscribe();
 | 
				
			||||||
        this.alwaysShowLoginFormObserver?.off();
 | 
					        this.alwaysShowLoginFormObserver?.off();
 | 
				
			||||||
 | 
					        this.loginObserver?.off();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -71,6 +71,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
 | 
				
			|||||||
    protected loginSuccessful = false;
 | 
					    protected loginSuccessful = false;
 | 
				
			||||||
    protected username = '';
 | 
					    protected username = '';
 | 
				
			||||||
    protected alwaysShowLoginFormObserver?: CoreEventObserver;
 | 
					    protected alwaysShowLoginFormObserver?: CoreEventObserver;
 | 
				
			||||||
 | 
					    protected loginObserver?: CoreEventObserver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
        protected fb: FormBuilder,
 | 
					        protected fb: FormBuilder,
 | 
				
			||||||
@ -81,6 +82,11 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
 | 
				
			|||||||
        this.credForm = fb.group({
 | 
					        this.credForm = fb.group({
 | 
				
			||||||
            password: ['', Validators.required],
 | 
					            password: ['', Validators.required],
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Listen to LOGIN event to determine if login was successful, since the login can be done using QR, biometric, etc.
 | 
				
			||||||
 | 
					        this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, () => {
 | 
				
			||||||
 | 
					            this.loginSuccessful = true;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -151,10 +157,12 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                config: this.siteConfig,
 | 
					                config: this.siteConfig,
 | 
				
			||||||
                loginSuccessful: this.loginSuccessful,
 | 
					                loginSuccessful: this.loginSuccessful,
 | 
				
			||||||
 | 
					                siteId: this.siteId,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            this.siteId,
 | 
					            this.siteId,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        this.alwaysShowLoginFormObserver?.off();
 | 
					        this.alwaysShowLoginFormObserver?.off();
 | 
				
			||||||
 | 
					        this.loginObserver?.off();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -190,7 +198,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (!this.eventThrown && !this.viewLeft) {
 | 
					        if (!this.eventThrown && !this.viewLeft) {
 | 
				
			||||||
            this.eventThrown = true;
 | 
					            this.eventThrown = true;
 | 
				
			||||||
            CoreEvents.trigger(CoreEvents.LOGIN_SITE_CHECKED, { config: this.siteConfig });
 | 
					            CoreEvents.trigger(CoreEvents.LOGIN_SITE_CHECKED, { config: this.siteConfig, siteId: this.siteId });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.isBrowserSSO = CoreLoginHelper.isSSOLoginNeeded(this.siteConfig.typeoflogin);
 | 
					        this.isBrowserSSO = CoreLoginHelper.isSSOLoginNeeded(this.siteConfig.typeoflogin);
 | 
				
			||||||
@ -261,8 +269,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
 | 
				
			|||||||
            this.credForm.controls['password'].reset();
 | 
					            this.credForm.controls['password'].reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Go to the site initial page.
 | 
					            // Go to the site initial page.
 | 
				
			||||||
            this.loginSuccessful = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await CoreNavigator.navigateToSiteHome({
 | 
					            await CoreNavigator.navigateToSiteHome({
 | 
				
			||||||
                params: this.redirectData,
 | 
					                params: this.redirectData,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
				
			|||||||
@ -148,8 +148,15 @@ export class CoreStylesService {
 | 
				
			|||||||
            this.removeSite(site.getId());
 | 
					            this.removeSite(site.getId());
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Load temporary styles when site config is checked in login.
 | 
					        // Load temporary styles when site config is checked in login/reconnect.
 | 
				
			||||||
        CoreEvents.on(CoreEvents.LOGIN_SITE_CHECKED, (data) => {
 | 
					        CoreEvents.on(CoreEvents.LOGIN_SITE_CHECKED, (data) => {
 | 
				
			||||||
 | 
					            if (data.siteId) {
 | 
				
			||||||
 | 
					                // Reconnecting to a site, enable the site styles.
 | 
				
			||||||
 | 
					                this.enableSiteStyles(data.siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.loadTmpStyles(data.config).catch((error) => {
 | 
					            this.loadTmpStyles(data.config).catch((error) => {
 | 
				
			||||||
                this.logger.error('Error loading tmp styles', error);
 | 
					                this.logger.error('Error loading tmp styles', error);
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
@ -163,8 +170,9 @@ export class CoreStylesService {
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // The tmp styles are from a site that wasn't added in the end. Just remove them.
 | 
					            // User didn't access the site, unload tmp styles and site styles if any.
 | 
				
			||||||
            this.unloadTmpStyles();
 | 
					            this.unloadTmpStyles();
 | 
				
			||||||
 | 
					            this.clear();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1443,7 +1443,7 @@ export class CoreSitesProvider {
 | 
				
			|||||||
    async login(siteId: string): Promise<void> {
 | 
					    async login(siteId: string): Promise<void> {
 | 
				
			||||||
        await CoreConfig.set(CORE_SITE_CURRENT_SITE_ID_CONFIG, siteId);
 | 
					        await CoreConfig.set(CORE_SITE_CURRENT_SITE_ID_CONFIG, siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CoreEvents.trigger(CoreEvents.LOGIN, {}, siteId);
 | 
					        CoreEvents.trigger(CoreEvents.LOGIN, { siteId }, siteId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -72,7 +72,7 @@ describe('CoreSitesProvider', () => {
 | 
				
			|||||||
            getCurrentSiteId: () => '42',
 | 
					            getCurrentSiteId: () => '42',
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CoreEvents.trigger(CoreEvents.LOGIN, {}, '42');
 | 
					        CoreEvents.trigger(CoreEvents.LOGIN, { siteId: '42' }, '42');
 | 
				
			||||||
        // Wait the event to be processed.
 | 
					        // Wait the event to be processed.
 | 
				
			||||||
        await CoreWait.nextTick();
 | 
					        await CoreWait.nextTick();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -56,6 +56,7 @@ export interface CoreEventsData {
 | 
				
			|||||||
    [CoreEvents.IAB_LOAD_START]: InAppBrowserEvent;
 | 
					    [CoreEvents.IAB_LOAD_START]: InAppBrowserEvent;
 | 
				
			||||||
    [CoreEvents.IAB_LOAD_STOP]: InAppBrowserEvent;
 | 
					    [CoreEvents.IAB_LOAD_STOP]: InAppBrowserEvent;
 | 
				
			||||||
    [CoreEvents.IAB_MESSAGE]: Record<string, unknown>;
 | 
					    [CoreEvents.IAB_MESSAGE]: Record<string, unknown>;
 | 
				
			||||||
 | 
					    [CoreEvents.LOGIN]: { siteId: string };
 | 
				
			||||||
    [CoreEvents.LOGIN_SITE_CHECKED]: CoreEventLoginSiteCheckedData;
 | 
					    [CoreEvents.LOGIN_SITE_CHECKED]: CoreEventLoginSiteCheckedData;
 | 
				
			||||||
    [CoreEvents.LOGIN_SITE_UNCHECKED]: CoreEventLoginSiteUncheckedData;
 | 
					    [CoreEvents.LOGIN_SITE_UNCHECKED]: CoreEventLoginSiteUncheckedData;
 | 
				
			||||||
    [CoreEvents.SEND_ON_ENTER_CHANGED]: CoreEventSendOnEnterChangedData;
 | 
					    [CoreEvents.SEND_ON_ENTER_CHANGED]: CoreEventSendOnEnterChangedData;
 | 
				
			||||||
@ -428,6 +429,7 @@ export type CoreEventActivityDataSentData = {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export type CoreEventLoginSiteCheckedData = {
 | 
					export type CoreEventLoginSiteCheckedData = {
 | 
				
			||||||
    config: CoreSitePublicConfigResponse;
 | 
					    config: CoreSitePublicConfigResponse;
 | 
				
			||||||
 | 
					    siteId?: string;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -436,6 +438,7 @@ export type CoreEventLoginSiteCheckedData = {
 | 
				
			|||||||
export type CoreEventLoginSiteUncheckedData = {
 | 
					export type CoreEventLoginSiteUncheckedData = {
 | 
				
			||||||
    config?: CoreSitePublicConfigResponse;
 | 
					    config?: CoreSitePublicConfigResponse;
 | 
				
			||||||
    loginSuccessful: boolean;
 | 
					    loginSuccessful: boolean;
 | 
				
			||||||
 | 
					    siteId?: string;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user