From abaf75fb294a796fc6c99904ab3b47a2367a3792 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 16 Mar 2017 09:03:22 +0000
Subject: [PATCH] #3527 fix - Added logout button and routing refactoring 

---
 securis/src/main/webapp/src/app/user.service.ts |   24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/securis/src/main/webapp/src/app/user.service.ts b/securis/src/main/webapp/src/app/user.service.ts
index 1d7e3e6..e4dac43 100644
--- a/securis/src/main/webapp/src/app/user.service.ts
+++ b/securis/src/main/webapp/src/app/user.service.ts
@@ -27,14 +27,14 @@
     params.append('password', password);
     let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
     return this.http.post('user/login', params.toString(), options)
-                    .map(this.mapLogin)
+                    .map((resp) => this.mapLogin(resp))
                     .catch(this.handleError);
   }
 
-  private mapLogin(res : Response) {
+  private mapLogin(res : Response) : string {
     let data = res.json();
-    //this.store.set('username', data.username);
-		//this.store.set('token', data.token);
+    this.store.set('username', data.username);
+		this.store.set('token', data.token);
     return <string>data.token;
   }    
 
@@ -45,16 +45,16 @@
     var token = this.store.get("token");
     let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
     return this.http.get('check', option)
-                    .map(this.mapCheck)
+                    .map((resp) => this.mapCheck(resp))
                     .catch(this.handleError);
   }
 
-  private mapCheck(res : Response) {
-    let body = res.json();
-    if (body.valid) {
-      //this.store.set('user', body.user);
+  private mapCheck(res : Response) : boolean {
+    let data = res.json();
+    if (data.valid) {
+      this.store.set('user', data.user);
     }
-    return body.valid;
+    return data.valid;
   }  
 
   existsToken() : Boolean {
@@ -63,10 +63,8 @@
 
   logout() : void {
     this.store.remove('user', 'token');
-    this.router.navigate(['Login']);
+    this.router.navigate(['public/login']);
   }
-
-
 
 
   private handleError (error: Response | any) {

--
Gitblit v1.3.2