forked from EVOgeek/Vmeda.Online
		
	Merge pull request #3089 from dpalou/MOBILE-3960
MOBILE-3960 config: Add new removeaccountonlogout config
This commit is contained in:
		
						commit
						81a3f0fa01
					
				| @ -77,8 +77,14 @@ | |||||||
|     <div class="ion-padding"> |     <div class="ion-padding"> | ||||||
|         <ion-button (click)="logout($event)" expand="block" color="danger" [attr.aria-label]="'core.mainmenu.logout' | translate" |         <ion-button (click)="logout($event)" expand="block" color="danger" [attr.aria-label]="'core.mainmenu.logout' | translate" | ||||||
|             class="ion-text-wrap"> |             class="ion-text-wrap"> | ||||||
|  |             <ng-container *ngIf="!removeAccountOnLogout"> | ||||||
|                 <ion-icon name="fas-sign-out-alt" slot="start" aria-hidden="true"></ion-icon> |                 <ion-icon name="fas-sign-out-alt" slot="start" aria-hidden="true"></ion-icon> | ||||||
|                 {{ 'core.mainmenu.logout' | translate }} |                 {{ '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> |         </ion-button> | ||||||
|     </div> |     </div> | ||||||
| </ion-footer> | </ion-footer> | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ | |||||||
| import { CoreConstants } from '@/core/constants'; | import { CoreConstants } from '@/core/constants'; | ||||||
| import { Component, OnDestroy, OnInit } from '@angular/core'; | import { Component, OnDestroy, OnInit } from '@angular/core'; | ||||||
| import { CoreSite, CoreSiteInfo } from '@classes/site'; | import { CoreSite, CoreSiteInfo } from '@classes/site'; | ||||||
|  | import { CoreFilter } from '@features/filter/services/filter'; | ||||||
| import { CoreLoginSitesComponent } from '@features/login/components/sites/sites'; | import { CoreLoginSitesComponent } from '@features/login/components/sites/sites'; | ||||||
| import { CoreLoginHelper } from '@features/login/services/login-helper'; | import { CoreLoginHelper } from '@features/login/services/login-helper'; | ||||||
| import { CoreUser, CoreUserProfile } from '@features/user/services/user'; | import { CoreUser, CoreUserProfile } from '@features/user/services/user'; | ||||||
| @ -40,6 +41,7 @@ import { Subscription } from 'rxjs'; | |||||||
| }) | }) | ||||||
| export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | ||||||
| 
 | 
 | ||||||
|  |     siteId?: string; | ||||||
|     siteInfo?: CoreSiteInfo; |     siteInfo?: CoreSiteInfo; | ||||||
|     siteName?: string; |     siteName?: string; | ||||||
|     siteLogo?: string; |     siteLogo?: string; | ||||||
| @ -50,6 +52,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | |||||||
|     loaded = false; |     loaded = false; | ||||||
|     user?: CoreUserProfile; |     user?: CoreUserProfile; | ||||||
|     displaySwitchAccount = true; |     displaySwitchAccount = true; | ||||||
|  |     removeAccountOnLogout = false; | ||||||
| 
 | 
 | ||||||
|     protected subscription!: Subscription; |     protected subscription!: Subscription; | ||||||
| 
 | 
 | ||||||
| @ -58,10 +61,12 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | |||||||
|      */ |      */ | ||||||
|     async ngOnInit(): Promise<void> { |     async ngOnInit(): Promise<void> { | ||||||
|         const currentSite = CoreSites.getRequiredCurrentSite(); |         const currentSite = CoreSites.getRequiredCurrentSite(); | ||||||
|  |         this.siteId = currentSite.getId(); | ||||||
|         this.siteInfo = currentSite.getInfo(); |         this.siteInfo = currentSite.getInfo(); | ||||||
|         this.siteName = currentSite.getSiteName(); |         this.siteName = currentSite.getSiteName(); | ||||||
|         this.siteUrl = currentSite.getURL(); |         this.siteUrl = currentSite.getURL(); | ||||||
|         this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount'); |         this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount'); | ||||||
|  |         this.removeAccountOnLogout = !!CoreConstants.CONFIG.removeaccountonlogout; | ||||||
| 
 | 
 | ||||||
|         this.loaded = true; |         this.loaded = true; | ||||||
| 
 | 
 | ||||||
| @ -167,9 +172,26 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | |||||||
|      * @param event Click event |      * @param event Click event | ||||||
|      */ |      */ | ||||||
|     async logout(event: Event): Promise<void> { |     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); |         await this.close(event); | ||||||
| 
 | 
 | ||||||
|         CoreSites.logout(true); |         await CoreSites.logout({ | ||||||
|  |             forceLogout: true, | ||||||
|  |             removeAccount: this.removeAccountOnLogout, | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -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. |      * @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. |      * @return Promise resolved when the user is logged out. | ||||||
|      */ |      */ | ||||||
|     async logout(forceLogout = false): Promise<void> { |     async logout(options: CoreSitesLogoutOptions = {}): Promise<void> { | ||||||
|         if (!this.currentSite) { |         if (!this.currentSite) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| @ -1195,7 +1195,7 @@ export class CoreSitesProvider { | |||||||
| 
 | 
 | ||||||
|         this.currentSite = undefined; |         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)); |             promises.push(this.setSiteLoggedOut(siteId)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -1203,6 +1203,10 @@ export class CoreSitesProvider { | |||||||
| 
 | 
 | ||||||
|         await CoreUtils.ignoreErrors(Promise.all(promises)); |         await CoreUtils.ignoreErrors(Promise.all(promises)); | ||||||
| 
 | 
 | ||||||
|  |         if (options.removeAccount) { | ||||||
|  |             await CoreSites.deleteSite(siteId); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         CoreEvents.trigger(CoreEvents.LOGOUT, {}, siteId); |         CoreEvents.trigger(CoreEvents.LOGOUT, {}, siteId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -1913,3 +1917,11 @@ export type CoreSitesLoginTokenResponse = { | |||||||
|     debuginfo?: string; |     debuginfo?: string; | ||||||
|     reproductionlink?: 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.
 | ||||||
|  | }; | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								src/types/config.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								src/types/config.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -61,4 +61,5 @@ export interface EnvironmentConfig { | |||||||
|     wsrequestqueuelimit: number; // Maximum number of requests allowed in the queue.
 |     wsrequestqueuelimit: number; // Maximum number of requests allowed in the queue.
 | ||||||
|     wsrequestqueuedelay: number; // Maximum number of miliseconds to wait before processing 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.
 |     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.
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user