diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.html b/src/core/features/mainmenu/components/user-menu/user-menu.html index 67562de15..572e8aa26 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.html +++ b/src/core/features/mainmenu/components/user-menu/user-menu.html @@ -77,8 +77,14 @@
- - {{ 'core.mainmenu.logout' | translate }} + + + {{ 'core.mainmenu.logout' | translate }} + + + + {{ 'core.login.removeaccount' | translate }} +
diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.ts b/src/core/features/mainmenu/components/user-menu/user-menu.ts index 31e0c9137..a43cb3f66 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.ts +++ b/src/core/features/mainmenu/components/user-menu/user-menu.ts @@ -15,6 +15,7 @@ import { CoreConstants } from '@/core/constants'; import { Component, OnDestroy, OnInit } from '@angular/core'; import { CoreSite, CoreSiteInfo } from '@classes/site'; +import { CoreFilter } from '@features/filter/services/filter'; import { CoreLoginSitesComponent } from '@features/login/components/sites/sites'; import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreUser, CoreUserProfile } from '@features/user/services/user'; @@ -40,6 +41,7 @@ import { Subscription } from 'rxjs'; }) export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { + siteId?: string; siteInfo?: CoreSiteInfo; siteName?: string; siteLogo?: string; @@ -50,6 +52,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { loaded = false; user?: CoreUserProfile; displaySwitchAccount = true; + removeAccountOnLogout = false; protected subscription!: Subscription; @@ -58,10 +61,12 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { */ async ngOnInit(): Promise { const currentSite = CoreSites.getRequiredCurrentSite(); + this.siteId = currentSite.getId(); this.siteInfo = currentSite.getInfo(); this.siteName = currentSite.getSiteName(); this.siteUrl = currentSite.getURL(); this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount'); + this.removeAccountOnLogout = !!CoreConstants.CONFIG.removeaccountonlogout; this.loaded = true; @@ -167,9 +172,26 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { * @param event Click event */ async logout(event: Event): Promise { + if (this.removeAccountOnLogout) { + // Ask confirm. + const siteName = this.siteName ? + await CoreFilter.formatText(this.siteName, { clean: true, singleLine: true, filter: false }, [], this.siteId) : + ''; + + try { + await CoreDomUtils.showDeleteConfirm('core.login.confirmdeletesite', { sitename: siteName }); + } catch (error) { + // User cancelled, stop. + return; + } + } + await this.close(event); - CoreSites.logout(true); + await CoreSites.logout({ + forceLogout: true, + removeAccount: this.removeAccountOnLogout, + }); } /** diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index cd233fa27..c20644f22 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -1184,7 +1184,7 @@ export class CoreSitesProvider { * @param forceLogout If true, site will be marked as logged out, no matter the value tool_mobile_forcelogout. * @return Promise resolved when the user is logged out. */ - async logout(forceLogout = false): Promise { + async logout(options: CoreSitesLogoutOptions = {}): Promise { if (!this.currentSite) { return; } @@ -1195,7 +1195,7 @@ export class CoreSitesProvider { this.currentSite = undefined; - if (forceLogout || (siteConfig && siteConfig.tool_mobile_forcelogout == '1')) { + if (options.forceLogout || (siteConfig && siteConfig.tool_mobile_forcelogout == '1')) { promises.push(this.setSiteLoggedOut(siteId)); } @@ -1203,6 +1203,10 @@ export class CoreSitesProvider { await CoreUtils.ignoreErrors(Promise.all(promises)); + if (options.removeAccount) { + await CoreSites.deleteSite(siteId); + } + CoreEvents.trigger(CoreEvents.LOGOUT, {}, siteId); } @@ -1913,3 +1917,11 @@ export type CoreSitesLoginTokenResponse = { debuginfo?: string; reproductionlink?: string; }; + +/** + * Options for logout. + */ +export type CoreSitesLogoutOptions = { + forceLogout?: boolean; // If true, site will be marked as logged out, no matter the value tool_mobile_forcelogout. + removeAccount?: boolean; // If true, site will be removed too after logout. +}; diff --git a/src/types/config.d.ts b/src/types/config.d.ts index ccbac9336..c5627bc99 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -61,4 +61,5 @@ export interface EnvironmentConfig { wsrequestqueuelimit: number; // Maximum number of requests allowed in the queue. wsrequestqueuedelay: number; // Maximum number of miliseconds to wait before processing the queue. calendarreminderdefaultvalue: number; // Initial value for default reminders (in seconds). User can change it later. + removeaccountonlogout?: boolean; // True to remove the account when the user clicks logout. Doesn't affect switch account. }