fix issue 1824: Move signoff to the sign-in route canActivate

This commit is contained in:
Steven Zou 2017-04-01 18:36:20 +08:00
parent da7d76ae0b
commit 5db2e387c1
2 changed files with 35 additions and 24 deletions

View File

@ -27,7 +27,7 @@ export class NavigatorComponent implements OnInit {
private selectedLang: string = enLang;
private appTitle: string = 'APP_TITLE.HARBOR';
constructor(
private session: SessionService,
private router: Router,
@ -36,8 +36,8 @@ export class NavigatorComponent implements OnInit {
private appConfigService: AppConfigService,
private msgHandler: MessageHandlerService,
private searchTrigger: SearchTriggerService) {
}
}
ngOnInit(): void {
this.selectedLang = this.translate.currentLang;
@ -80,8 +80,8 @@ export class NavigatorComponent implements OnInit {
public get canChangePassword(): boolean {
return this.session.getCurrentUser() &&
this.appConfigService.getConfig() &&
this.appConfigService.getConfig().auth_mode != 'ldap_auth';
this.appConfigService.getConfig() &&
this.appConfigService.getConfig().auth_mode != 'ldap_auth';
}
matchLang(lang: string): boolean {
@ -114,17 +114,14 @@ export class NavigatorComponent implements OnInit {
//Log out system
logOut(): void {
this.session.signOff()
.then(() => {
//Naviagte to the sign in route
this.router.navigate([CommonRoutes.EMBEDDED_SIGN_IN]);
this.session.clear();//Destroy session cache
})
.catch(error => {
this.msgHandler.handleError(error);
});
//Naviagte to the sign in route
//Appending 'signout' means destroy session cache
let navigatorExtra: NavigationExtras = {
queryParams: { "signout": true }
};
this.router.navigate([CommonRoutes.EMBEDDED_SIGN_IN], navigatorExtra);
//Confirm search result panel is close
this.searchTrigger.closeSearch(true);
this.searchTrigger.closeSearch(true);
}
//Switch languages
@ -136,7 +133,7 @@ export class NavigatorComponent implements OnInit {
//TODO:
console.error('Language ' + lang.trim() + ' is not suppoted');
}
setTimeout(()=>{
setTimeout(() => {
window.location.reload();
}, 500);
}

View File

@ -15,19 +15,33 @@ export class SignInGuard implements CanActivate, CanActivateChild {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> | boolean {
//If user has logged in, should not login again
return new Promise((resolve, reject) => {
let user = this.authService.getCurrentUser();
if (user === null) {
this.authService.retrieveUser()
//If signout appended
let queryParams = route.queryParams;
if (queryParams && queryParams['signout']) {
this.authService.signOff()
.then(() => {
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
return resolve(false);
this.authService.clear();//Destroy session cache
return resolve(true);
})
.catch(error => {
return resolve(true);
console.error(error);
return resolve(false);
});
} else {
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
return resolve(false);
let user = this.authService.getCurrentUser();
if (user === null) {
this.authService.retrieveUser()
.then(() => {
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
return resolve(false);
})
.catch(error => {
return resolve(true);
});
} else {
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
return resolve(false);
}
}
});
}