1
|
import {Injectable} from '@angular/core';
|
2
|
import {Http, Response, Headers, RequestOptions, URLSearchParams} from '@angular/http';
|
3
|
import {Observable} from 'rxjs/Observable';
|
4
|
import 'rxjs/add/observable/of';
|
5
|
import 'rxjs/add/operator/do';
|
6
|
import 'rxjs/add/operator/share';
|
7
|
|
8
|
import { CacheService } from '../shared/cache.service';
|
9
|
import {PersonInfo} from '../utils/entities/personInfo';
|
10
|
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
11
|
import {User,Session,MyJWT} from './utils/helper.class';
|
12
|
|
13
|
|
14
|
@Injectable()
|
15
|
export class LoginService {
|
16
|
|
17
|
constructor(private http: Http, public _cache: CacheService) {}
|
18
|
|
19
|
authenticate (username: string, password: string):any {
|
20
|
|
21
|
|
22
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
23
|
let options = new RequestOptions({ headers: headers });
|
24
|
let body = JSON.stringify( {"username":username, "password":password} );
|
25
|
|
26
|
return this.http.post(OpenaireProperties.getLoginAPIURL(), body,options)
|
27
|
.map(res => <any> res.json())
|
28
|
.map(res =>this.parse(res['data']));
|
29
|
|
30
|
|
31
|
// let url = OpenaireProperties.getLoginAPIURL()+"?username="+username+"&password="+password;
|
32
|
// let key = url;
|
33
|
// return this.http.get(url)
|
34
|
// .map(res => <any> res.json())
|
35
|
// .map(res =>this.parse(res['data']));
|
36
|
|
37
|
}
|
38
|
|
39
|
parse(data:any){
|
40
|
return MyJWT.parseUserInfo(data);
|
41
|
}
|
42
|
|
43
|
}
|