MOBILE-4606 login: Fix loginSuccessful calculation when authenticating
parent
3d393e7bdc
commit
e666fdc517
|
@ -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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,6 +162,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
|
||||||
this.siteId,
|
this.siteId,
|
||||||
);
|
);
|
||||||
this.alwaysShowLoginFormObserver?.off();
|
this.alwaysShowLoginFormObserver?.off();
|
||||||
|
this.loginObserver?.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,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,
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue