MOBILE-3960 config: Add new removeaccountonlogout config

main
Dani Palou 2022-02-02 12:33:04 +01:00
parent 9f63d7307c
commit e505f1370a
4 changed files with 46 additions and 5 deletions

View File

@ -77,8 +77,14 @@
<div class="ion-padding">
<ion-button (click)="logout($event)" expand="block" color="danger" [attr.aria-label]="'core.mainmenu.logout' | translate"
class="ion-text-wrap">
<ion-icon name="fas-sign-out-alt" slot="start" aria-hidden="true"></ion-icon>
{{ 'core.mainmenu.logout' | translate }}
<ng-container *ngIf="!removeAccountOnLogout">
<ion-icon name="fas-sign-out-alt" slot="start" aria-hidden="true"></ion-icon>
{{ 'core.mainmenu.logout' | translate }}
</ng-container>
<ng-container *ngIf="removeAccountOnLogout">
<ion-icon name="fas-trash" slot="start" aria-hidden="true"></ion-icon>
{{ 'core.login.removeaccount' | translate }}
</ng-container>
</ion-button>
</div>
</ion-footer>

View File

@ -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<void> {
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<void> {
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,
});
}
/**

View File

@ -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<void> {
async logout(options: CoreSitesLogoutOptions = {}): Promise<void> {
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.
};

View File

@ -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.
}