Skip to content

Commit d165b06

Browse files
authored
Merge pull request #4156 from dpalou/MOBILE-4606
Mobile 4606
2 parents 7140045 + e666fdc commit d165b06

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

src/core/features/login/pages/credentials/credentials.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
8080
protected urlToOpen?: string;
8181
protected valueChangeSubscription?: Subscription;
8282
protected alwaysShowLoginFormObserver?: CoreEventObserver;
83+
protected loginObserver?: CoreEventObserver;
8384

8485
constructor(
8586
protected fb: FormBuilder,
86-
) {}
87+
) {
88+
// Listen to LOGIN event to determine if login was successful, since the login can be done using QR, SSO, etc.
89+
this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, ({ siteId }) => {
90+
this.siteId = siteId;
91+
});
92+
}
8793

8894
/**
8995
* @inheritdoc
@@ -297,14 +303,12 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
297303
try {
298304
const data = await CoreSites.getUserToken(siteUrl, username, password);
299305

300-
const id = await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
306+
await CoreSites.newSite(data.siteUrl, data.token, data.privateToken);
301307

302308
// Reset fields so the data is not in the view anymore.
303309
this.credForm.controls['username'].reset();
304310
this.credForm.controls['password'].reset();
305311

306-
this.siteId = id;
307-
308312
await CoreNavigator.navigateToSiteHome({ params: { urlToOpen: this.urlToOpen } });
309313
} catch (error) {
310314
if (error instanceof CoreSiteError && CoreLoginHelper.isAppUnsupportedError(error)) {
@@ -379,6 +383,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
379383
);
380384
this.valueChangeSubscription?.unsubscribe();
381385
this.alwaysShowLoginFormObserver?.off();
386+
this.loginObserver?.off();
382387
}
383388

384389
}

src/core/features/login/pages/reconnect/reconnect.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
7171
protected loginSuccessful = false;
7272
protected username = '';
7373
protected alwaysShowLoginFormObserver?: CoreEventObserver;
74+
protected loginObserver?: CoreEventObserver;
7475

7576
constructor(
7677
protected fb: FormBuilder,
@@ -81,6 +82,11 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
8182
this.credForm = fb.group({
8283
password: ['', Validators.required],
8384
});
85+
86+
// Listen to LOGIN event to determine if login was successful, since the login can be done using QR, biometric, etc.
87+
this.loginObserver = CoreEvents.on(CoreEvents.LOGIN, () => {
88+
this.loginSuccessful = true;
89+
});
8490
}
8591

8692
/**
@@ -151,10 +157,12 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
151157
{
152158
config: this.siteConfig,
153159
loginSuccessful: this.loginSuccessful,
160+
siteId: this.siteId,
154161
},
155162
this.siteId,
156163
);
157164
this.alwaysShowLoginFormObserver?.off();
165+
this.loginObserver?.off();
158166
}
159167

160168
/**
@@ -190,7 +198,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
190198

191199
if (!this.eventThrown && !this.viewLeft) {
192200
this.eventThrown = true;
193-
CoreEvents.trigger(CoreEvents.LOGIN_SITE_CHECKED, { config: this.siteConfig });
201+
CoreEvents.trigger(CoreEvents.LOGIN_SITE_CHECKED, { config: this.siteConfig, siteId: this.siteId });
194202
}
195203

196204
this.isBrowserSSO = CoreLoginHelper.isSSOLoginNeeded(this.siteConfig.typeoflogin);
@@ -261,8 +269,6 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
261269
this.credForm.controls['password'].reset();
262270

263271
// Go to the site initial page.
264-
this.loginSuccessful = true;
265-
266272
await CoreNavigator.navigateToSiteHome({
267273
params: this.redirectData,
268274
});

src/core/features/styles/services/styles.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ export class CoreStylesService {
148148
this.removeSite(site.getId());
149149
});
150150

151-
// Load temporary styles when site config is checked in login.
151+
// Load temporary styles when site config is checked in login/reconnect.
152152
CoreEvents.on(CoreEvents.LOGIN_SITE_CHECKED, (data) => {
153+
if (data.siteId) {
154+
// Reconnecting to a site, enable the site styles.
155+
this.enableSiteStyles(data.siteId);
156+
157+
return;
158+
}
159+
153160
this.loadTmpStyles(data.config).catch((error) => {
154161
this.logger.error('Error loading tmp styles', error);
155162
});
@@ -163,8 +170,9 @@ export class CoreStylesService {
163170
return;
164171
}
165172

166-
// The tmp styles are from a site that wasn't added in the end. Just remove them.
173+
// User didn't access the site, unload tmp styles and site styles if any.
167174
this.unloadTmpStyles();
175+
this.clear();
168176
});
169177
}
170178

src/core/services/sites.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ export class CoreSitesProvider {
14431443
async login(siteId: string): Promise<void> {
14441444
await CoreConfig.set(CORE_SITE_CURRENT_SITE_ID_CONFIG, siteId);
14451445

1446-
CoreEvents.trigger(CoreEvents.LOGIN, {}, siteId);
1446+
CoreEvents.trigger(CoreEvents.LOGIN, { siteId }, siteId);
14471447
}
14481448

14491449
/**

src/core/services/tests/sites.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('CoreSitesProvider', () => {
7272
getCurrentSiteId: () => '42',
7373
});
7474

75-
CoreEvents.trigger(CoreEvents.LOGIN, {}, '42');
75+
CoreEvents.trigger(CoreEvents.LOGIN, { siteId: '42' }, '42');
7676
// Wait the event to be processed.
7777
await CoreWait.nextTick();
7878

src/core/singletons/events.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface CoreEventsData {
5656
[CoreEvents.IAB_LOAD_START]: InAppBrowserEvent;
5757
[CoreEvents.IAB_LOAD_STOP]: InAppBrowserEvent;
5858
[CoreEvents.IAB_MESSAGE]: Record<string, unknown>;
59+
[CoreEvents.LOGIN]: { siteId: string };
5960
[CoreEvents.LOGIN_SITE_CHECKED]: CoreEventLoginSiteCheckedData;
6061
[CoreEvents.LOGIN_SITE_UNCHECKED]: CoreEventLoginSiteUncheckedData;
6162
[CoreEvents.SEND_ON_ENTER_CHANGED]: CoreEventSendOnEnterChangedData;
@@ -428,6 +429,7 @@ export type CoreEventActivityDataSentData = {
428429
*/
429430
export type CoreEventLoginSiteCheckedData = {
430431
config: CoreSitePublicConfigResponse;
432+
siteId?: string;
431433
};
432434

433435
/**
@@ -436,6 +438,7 @@ export type CoreEventLoginSiteCheckedData = {
436438
export type CoreEventLoginSiteUncheckedData = {
437439
config?: CoreSitePublicConfigResponse;
438440
loginSuccessful: boolean;
441+
siteId?: string;
439442
};
440443

441444
/**

0 commit comments

Comments
 (0)