| .. | .. |
|---|
| 27 | 27 | params.append('password', password); |
|---|
| 28 | 28 | let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })}); |
|---|
| 29 | 29 | return this.http.post('user/login', params.toString(), options) |
|---|
| 30 | | - .map(this.mapLogin) |
|---|
| 30 | + .map((resp) => this.mapLogin(resp)) |
|---|
| 31 | 31 | .catch(this.handleError); |
|---|
| 32 | 32 | } |
|---|
| 33 | 33 | |
|---|
| 34 | | - private mapLogin(res : Response) { |
|---|
| 34 | + private mapLogin(res : Response) : string { |
|---|
| 35 | 35 | 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); |
|---|
| 38 | 38 | return <string>data.token; |
|---|
| 39 | 39 | } |
|---|
| 40 | 40 | |
|---|
| .. | .. |
|---|
| 45 | 45 | var token = this.store.get("token"); |
|---|
| 46 | 46 | let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) }); |
|---|
| 47 | 47 | return this.http.get('check', option) |
|---|
| 48 | | - .map(this.mapCheck) |
|---|
| 48 | + .map((resp) => this.mapCheck(resp)) |
|---|
| 49 | 49 | .catch(this.handleError); |
|---|
| 50 | 50 | } |
|---|
| 51 | 51 | |
|---|
| 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); |
|---|
| 56 | 56 | } |
|---|
| 57 | | - return body.valid; |
|---|
| 57 | + return data.valid; |
|---|
| 58 | 58 | } |
|---|
| 59 | 59 | |
|---|
| 60 | 60 | existsToken() : Boolean { |
|---|
| .. | .. |
|---|
| 63 | 63 | |
|---|
| 64 | 64 | logout() : void { |
|---|
| 65 | 65 | this.store.remove('user', 'token'); |
|---|
| 66 | | - this.router.navigate(['Login']); |
|---|
| 66 | + this.router.navigate(['public/login']); |
|---|
| 67 | 67 | } |
|---|
| 68 | | - |
|---|
| 69 | | - |
|---|
| 70 | 68 | |
|---|
| 71 | 69 | |
|---|
| 72 | 70 | private handleError (error: Response | any) { |
|---|