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