forked from CIT/Vmeda.Online
		
	MOBILE-3117 login: Fix logout on reconnect
This commit is contained in:
		
							parent
							
								
									ada49974f4
								
							
						
					
					
						commit
						a347a6d4ed
					
				| @ -25,6 +25,7 @@ import { CoreCustomURLSchemesProvider } from '@providers/urlschemes'; | ||||
| import { CoreLoginHelperProvider } from '@core/login/providers/helper'; | ||||
| import { Keyboard } from '@ionic-native/keyboard'; | ||||
| import { ScreenOrientation } from '@ionic-native/screen-orientation'; | ||||
| import { CoreLoginSitesPage } from '@core/login/pages/sites/sites'; | ||||
| 
 | ||||
| @Component({ | ||||
|     templateUrl: 'app.html' | ||||
| @ -74,7 +75,9 @@ export class MoodleMobileApp implements OnInit { | ||||
|     ngOnInit(): void { | ||||
|         this.eventsProvider.on(CoreEventsProvider.LOGOUT, () => { | ||||
|             // Go to sites page when user is logged out.
 | ||||
|             this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage'); | ||||
|             // Due to DeepLinker, we need to use the ViewCtrl instead of name.
 | ||||
|             // Otherwise some pages are re-created when they shouldn't.
 | ||||
|             this.appProvider.getRootNavController().setRoot(CoreLoginSitesPage); | ||||
| 
 | ||||
|             // Unload lang custom strings.
 | ||||
|             this.langProvider.clearCustomStrings(); | ||||
|  | ||||
| @ -39,7 +39,7 @@ | ||||
|                 <ion-grid> | ||||
|                     <ion-row> | ||||
|                         <ion-col> | ||||
|                             <a ion-button block color="light" (click)="cancel()">{{ 'core.login.cancel' | translate }}</a> | ||||
|                             <a ion-button block color="light" (click)="cancel($event)">{{ 'core.login.cancel' | translate }}</a> | ||||
|                         </ion-col> | ||||
|                         <ion-col> | ||||
|                             <button ion-button block [disabled]="!credForm.valid">{{ 'core.login.loginbutton' | translate }}</button> | ||||
|  | ||||
| @ -101,13 +101,16 @@ export class CoreLoginReconnectPage { | ||||
| 
 | ||||
|     /** | ||||
|      * Cancel reconnect. | ||||
|      * | ||||
|      * @param {Event} [e] Event. | ||||
|      */ | ||||
|     cancel(): void { | ||||
|         this.sitesProvider.logout().catch(() => { | ||||
|             // Ignore errors (shouldn't happen).
 | ||||
|         }).finally(() => { | ||||
|             this.navCtrl.setRoot('CoreLoginSitesPage'); | ||||
|         }); | ||||
|     cancel(e?: Event): void { | ||||
|         if (e) { | ||||
|             e.preventDefault(); | ||||
|             e.stopPropagation(); | ||||
|         } | ||||
| 
 | ||||
|         this.sitesProvider.logout(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -27,7 +27,6 @@ import { CoreConfigConstants } from '../configconstants'; | ||||
| import { CoreSite } from '@classes/site'; | ||||
| import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; | ||||
| import { Md5 } from 'ts-md5/dist/md5'; | ||||
| import { Location } from '@angular/common'; | ||||
| import { WP_PROVIDER } from '@app/app.module'; | ||||
| 
 | ||||
| /** | ||||
| @ -326,7 +325,7 @@ export class CoreSitesProvider { | ||||
| 
 | ||||
|     constructor(logger: CoreLoggerProvider, private http: HttpClient, private sitesFactory: CoreSitesFactoryProvider, | ||||
|             private appProvider: CoreAppProvider, private translate: TranslateService, private urlUtils: CoreUrlUtilsProvider, | ||||
|             private eventsProvider: CoreEventsProvider,  private textUtils: CoreTextUtilsProvider, private location: Location, | ||||
|             private eventsProvider: CoreEventsProvider,  private textUtils: CoreTextUtilsProvider, | ||||
|             private utils: CoreUtilsProvider, private injector: Injector) { | ||||
|         this.logger = logger.getInstance('CoreSitesProvider'); | ||||
| 
 | ||||
| @ -1221,14 +1220,12 @@ export class CoreSitesProvider { | ||||
|      * @return {Promise<any>} Promise resolved when the user is logged out. | ||||
|      */ | ||||
|     logout(): Promise<any> { | ||||
|         if (!this.currentSite) { | ||||
|             // Already logged out.
 | ||||
|             return Promise.resolve(); | ||||
|         } | ||||
|         let siteId; | ||||
|         const promises = []; | ||||
| 
 | ||||
|         const siteId = this.currentSite.getId(), | ||||
|             siteConfig = this.currentSite.getStoredConfig(), | ||||
|             promises = []; | ||||
|         if (this.currentSite) { | ||||
|             const siteConfig = this.currentSite.getStoredConfig(); | ||||
|             siteId = this.currentSite.getId(); | ||||
| 
 | ||||
|             this.currentSite = undefined; | ||||
| 
 | ||||
| @ -1237,11 +1234,9 @@ export class CoreSitesProvider { | ||||
|             } | ||||
| 
 | ||||
|             promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, { id: 1 })); | ||||
|         } | ||||
| 
 | ||||
|         return Promise.all(promises).finally(() => { | ||||
|             // Due to DeepLinker, we need to remove the path from the URL, otherwise some pages are re-created when they shouldn't.
 | ||||
|             this.location.replaceState(''); | ||||
| 
 | ||||
|             this.eventsProvider.trigger(CoreEventsProvider.LOGOUT, {}, siteId); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user