rsanchez
2017-03-16 abaf75fb294a796fc6c99904ab3b47a2367a3792
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) {