rsanchez
2017-03-16 abaf75fb294a796fc6c99904ab3b47a2367a3792
#3527 fix - Added logout button and routing refactoring 
10 files modified
changed files
securis/src/main/webapp/src/app/app.routes.ts patch | view | blame | history
securis/src/main/webapp/src/app/footer.component.html patch | view | blame | history
securis/src/main/webapp/src/app/home.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/license.list.component.html patch | view | blame | history
securis/src/main/webapp/src/app/login.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/menu.component.html patch | view | blame | history
securis/src/main/webapp/src/app/menu.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/nomenu.component.html patch | view | blame | history
securis/src/main/webapp/src/app/pack.list.component.html patch | view | blame | history
securis/src/main/webapp/src/app/user.service.ts patch | view | blame | history
securis/src/main/webapp/src/app/app.routes.ts
....@@ -8,8 +8,10 @@
88 import { LoginFormComponent } from './login.form.component';
99
1010 const routes: Routes = [
11
- // {path: '', redirectTo: '/packs', pathMatch: 'full'},
12
- {path: 'menu', component: MenuComponent,
11
+ {path: 'public', component: NoMenuComponent, children: [
12
+ {path: 'login', component: LoginFormComponent },
13
+ },
14
+ {path: '', component: MenuComponent,
1315 children: [
1416 {path: 'packs', children: [
1517 {path: '', component: PackListComponent },
....@@ -17,11 +19,6 @@
1719 ]}
1820 ]
1921 },
20
- {path: 'nomenu', component: NoMenuComponent,
21
- children: [
22
- {path: 'login', component: LoginFormComponent }
23
- ]
24
- }
2522
2623 ];
2724 /* {path: 'product', component: DashboardProductComponent, children: [
securis/src/main/webapp/src/app/footer.component.html
....@@ -1,7 +1,6 @@
1
- <td-layout-footer>
21 <div layout="row" layout-align="start center" flex>
32 <div flex layout="row" layout-align="start center">v. {{securisVersion}}</div>
43 <div flex layout="row" layout-align="center center"><a href="http://www.curistec.com/" target="_blank">CurisTec</a>&nbsp;©2017</div>
54 <div flex></div>
65 </div>
7
- </td-layout-footer>
6
+
securis/src/main/webapp/src/app/home.component.ts
....@@ -53,7 +53,6 @@
5353 }
5454
5555 ngOnInit(): void {
56
- this.router.navigateByUrl('nomenu/login');
5756 }
5857
5958 ngAfterViewInit(): void {
securis/src/main/webapp/src/app/license.list.component.html
....@@ -66,7 +66,7 @@
6666 </div>
6767 </template>
6868 </td-data-table>
69
- <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= pagingBar.pageSize" >
69
+ <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= 10" >
7070 <span i18n td-paging-bar-label hide-xs>Rows per page:</span> {{pagingBar.range}} <span hide-xs>of {{pagingBar.total}}</span>
7171 </td-paging-bar>
7272 </div>
securis/src/main/webapp/src/app/login.form.component.ts
....@@ -26,7 +26,7 @@
2626 public login() {
2727 this.userService.login(this.data.username, this.data.password).subscribe(
2828 token => {
29
- this.router.navigateByUrl("menu/packs");
29
+ this.router.navigateByUrl("packs");
3030 },
3131 errMsg => this.toaster.error(errMsg, 'Login error'));
3232 }
securis/src/main/webapp/src/app/menu.component.html
....@@ -31,8 +31,16 @@
3131 </md-nav-list>
3232
3333 <td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
34
+ <div td-toolbar-content layout="row" layout-align="start center" flex>
35
+ <span flex ></span>
36
+ <button md-icon-button (click)="logout()">
37
+ <md-icon color="white">exit_to_app</md-icon>
38
+ </button>
39
+ </div>
3440 <router-outlet></router-outlet>
35
- <app-footer></app-footer>
41
+ <td-layout-footer>
42
+ <app-footer></app-footer>
43
+ </td-layout-footer>
3644 </td-layout-nav>
3745 </td-layout>
3846
securis/src/main/webapp/src/app/menu.component.ts
....@@ -22,10 +22,16 @@
2222 this.userService.isLoggedIn().subscribe(authOk => {
2323 let isLoggedIn = authOk.valueOf();
2424 if (!isLoggedIn) {
25
- this.router.navigateByUrl('nomenu/login');
25
+ this.router.navigateByUrl('public/login');
26
+ } else {
27
+ this.router.navigate(['packs']);
2628 }
2729 } ,
28
- err => /* Show message */ this.router.navigateByUrl('nomenu/login'));
30
+ err => /* Show message */ this.router.navigateByUrl('public/login'));
31
+ }
32
+
33
+ public logout() {
34
+ this.userService.logout();
2935 }
3036
3137 public closeMenu() {
securis/src/main/webapp/src/app/nomenu.component.html
....@@ -1,4 +1,6 @@
11 <td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
22 <router-outlet></router-outlet>
3
- <app-footer></app-footer>
3
+ <td-layout-footer>
4
+ <app-footer></app-footer>
5
+ </td-layout-footer>
46 </td-layout-nav>
securis/src/main/webapp/src/app/pack.list.component.html
....@@ -49,7 +49,7 @@
4949 </div>
5050 </template>
5151 </td-data-table>
52
- <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= pagingBar.pageSize">
52
+ <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= 10">
5353 <span td-paging-bar-label hide-xs>Rows per page:</span> {{pagingBar.range}} <span hide-xs>of {{pagingBar.total}}</span>
5454 </td-paging-bar>
5555 </div>
securis/src/main/webapp/src/app/user.service.ts
....@@ -27,14 +27,14 @@
2727 params.append('password', password);
2828 let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
2929 return this.http.post('user/login', params.toString(), options)
30
- .map(this.mapLogin)
30
+ .map((resp) => this.mapLogin(resp))
3131 .catch(this.handleError);
3232 }
3333
34
- private mapLogin(res : Response) {
34
+ private mapLogin(res : Response) : string {
3535 let data = res.json();
36
- //this.store.set('username', data.username);
37
- //this.store.set('token', data.token);
36
+ this.store.set('username', data.username);
37
+ this.store.set('token', data.token);
3838 return <string>data.token;
3939 }
4040
....@@ -45,16 +45,16 @@
4545 var token = this.store.get("token");
4646 let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
4747 return this.http.get('check', option)
48
- .map(this.mapCheck)
48
+ .map((resp) => this.mapCheck(resp))
4949 .catch(this.handleError);
5050 }
5151
52
- private mapCheck(res : Response) {
53
- let body = res.json();
54
- if (body.valid) {
55
- //this.store.set('user', body.user);
52
+ private mapCheck(res : Response) : boolean {
53
+ let data = res.json();
54
+ if (data.valid) {
55
+ this.store.set('user', data.user);
5656 }
57
- return body.valid;
57
+ return data.valid;
5858 }
5959
6060 existsToken() : Boolean {
....@@ -63,10 +63,8 @@
6363
6464 logout() : void {
6565 this.store.remove('user', 'token');
66
- this.router.navigate(['Login']);
66
+ this.router.navigate(['public/login']);
6767 }
68
-
69
-
7068
7169
7270 private handleError (error: Response | any) {