Make army overview visible public and rework login/logout routings
parent
263651adb0
commit
b1a82b0c45
|
@ -15,7 +15,10 @@
|
|||
<div class="collapse navbar-collapse" id="mynavbar">
|
||||
|
||||
<ul class="nav navbar-nav">
|
||||
<li *ngIf="loginService.isLoggedIn()" routerLinkActive="active">
|
||||
<li *ngIf="!loginService.isLoggedIn()" routerLinkActive="active">
|
||||
<a routerLink='/login' class="link">Login</a>
|
||||
</li>
|
||||
<li routerLinkActive="active">
|
||||
<a routerLink='/cc-overview' class="link">Armeeübersicht</a>
|
||||
</li>
|
||||
<li *ngIf="loginService.isLoggedIn()" routerLinkActive="active">
|
||||
|
|
|
@ -47,7 +47,7 @@ export class AppComponent {
|
|||
|
||||
logout() {
|
||||
this.loginService.logout();
|
||||
this.router.navigate(['login']);
|
||||
this.router.navigate(['cc-overview']);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,10 @@ import {armyRoutes, armyRoutingComponents} from "./army/army.routing";
|
|||
export const appRoutes: Routes = [
|
||||
|
||||
{path: 'cc-overview', children: armyRoutes},
|
||||
{path: '', redirectTo: '/cc-overview', pathMatch: 'full'},
|
||||
|
||||
{path: 'login', component: LoginComponent},
|
||||
{path: 'cc-users', children: usersRoutes, canActivate: [LoginGuard]},
|
||||
{path: '', redirectTo: '/cc-users', pathMatch: 'full'},
|
||||
|
||||
{path: 'cc-squads', children: squadsRoutes, canActivate: [LoginGuard]},
|
||||
{path: 'cc-decorations', children: decorationsRoutes, canActivate: [LoginGuard]},
|
||||
{path: 'cc-ranks', children: ranksRoutes, canActivate: [LoginGuard]},
|
||||
|
|
|
@ -25,8 +25,8 @@ export class LoginComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
// reset login status
|
||||
this.loginService.logout();
|
||||
// get return url from route parameters or default to '/'
|
||||
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||
// redirect to user overview on success
|
||||
this.returnUrl = '/cc-users'
|
||||
}
|
||||
|
||||
login(username: string, password: string) {
|
||||
|
@ -41,7 +41,7 @@ export class LoginComponent implements OnInit {
|
|||
this.showErrorLabel = true;
|
||||
setTimeout(() => {
|
||||
this.showErrorLabel = false;
|
||||
}, 4000)
|
||||
}, 4000);
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ export class HttpClient {
|
|||
|
||||
createAuthorizationHeader() {
|
||||
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
|
||||
if (currentUser) {
|
||||
if (new Date().getTime() <= Date.parse(currentUser.tokenExpireDate)) {
|
||||
let headers = new Headers();
|
||||
headers.append('x-access-token', currentUser.token);
|
||||
|
@ -22,6 +23,7 @@ export class HttpClient {
|
|||
this.router.navigate(['/login'])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get(url, searchParams?) {
|
||||
let headers = this.createAuthorizationHeader();
|
||||
|
|
Loading…
Reference in New Issue