From 199b9ae1c2818713bbb1a33831c46fb505e997d4 Mon Sep 17 00:00:00 2001
From: César Calvo <ccalvo@curisit.net>
Date: Wed, 15 Mar 2017 15:22:43 +0000
Subject: [PATCH] #3527 - Main menu

---
 securis/src/main/webapp/src/app/user.service.ts |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/securis/src/main/webapp/src/app/user.service.ts b/securis/src/main/webapp/src/app/user.service.ts
index 04f5cb7..1d7e3e6 100644
--- a/securis/src/main/webapp/src/app/user.service.ts
+++ b/securis/src/main/webapp/src/app/user.service.ts
@@ -12,6 +12,8 @@
 @Injectable()
 export class UserService {
 
+  count : number = 0;
+
   constructor(private $L: LocaleService,
               private router: Router,
               private store: LocalStorageService, 
@@ -25,31 +27,35 @@
     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((res: Response) => {
-                        let data = res.json();
-                        this.store.set('username', username);
-				                this.store.set('token', data.token);
-                        return <string>data.token;
-                      })
-                    .catch((r) => this.handleError(r));
+                    .map(this.mapLogin)
+                    .catch(this.handleError);
   }
+
+  private mapLogin(res : Response) {
+    let data = res.json();
+    //this.store.set('username', data.username);
+		//this.store.set('token', data.token);
+    return <string>data.token;
+  }    
 
   isLoggedIn() : Observable<Boolean> {
     if (!this.existsToken()) {
       return Observable.of(false);
     }
     var token = this.store.get("token");
-    return this.http.get('check', new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) }))
-                    .map((res: Response) => {
-                        let body = res.json();
-                        if (body.valid) {
-                          this.store.set('user', body.user);
-                        }
-                        return body.valid;
-                      })
-                    .catch((r) => this.handleError(r))
-                    .catch(() => Observable.of(false));
+    let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
+    return this.http.get('check', option)
+                    .map(this.mapCheck)
+                    .catch(this.handleError);
   }
+
+  private mapCheck(res : Response) {
+    let body = res.json();
+    if (body.valid) {
+      //this.store.set('user', body.user);
+    }
+    return body.valid;
+  }  
 
   existsToken() : Boolean {
     return this.store.get("token") !== null;
@@ -60,6 +66,9 @@
     this.router.navigate(['Login']);
   }
 
+
+
+
   private handleError (error: Response | any) {
     // In a real world app, we might use a remote logging infrastructure
     let errMsg: string;

--
Gitblit v1.3.2