mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
#33 draft gulp
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Injectable} from "angular2/core";
|
||||
import {Injectable} from 'angular2/core';
|
||||
import {Observable} from 'rxjs/Rx';
|
||||
import {Http, Headers, URLSearchParams, Response} from 'angular2/http';
|
||||
|
||||
@@ -6,12 +6,12 @@ declare var xml2json:any;
|
||||
|
||||
@Injectable()
|
||||
export class Authentication {
|
||||
token: string;
|
||||
token:string;
|
||||
|
||||
private _host: string = 'http://192.168.99.100:8080';
|
||||
private _baseUrl: string = this._host + '/alfresco/service/api/';
|
||||
private _host:string = 'http://192.168.99.100:8080';
|
||||
private _baseUrl:string = this._host + '/alfresco/service/api/';
|
||||
|
||||
constructor(public http: Http) {
|
||||
constructor(public http:Http) {
|
||||
this.token = localStorage.getItem('token');
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export class Authentication {
|
||||
|
||||
return this.http.get(this._baseUrl + 'login', {search: searchParams})
|
||||
.map((res:any) => {
|
||||
let data = JSON.parse(xml2json(res.text(),' '));
|
||||
let data = JSON.parse(xml2json(res.text(), ' '));
|
||||
this.token = data.ticket;
|
||||
this.saveJwt(this.token);
|
||||
})
|
||||
@@ -42,16 +42,16 @@ export class Authentication {
|
||||
}
|
||||
|
||||
loginPost(username:string, password:string) {
|
||||
var credentials = "{ username: " + username+ ", password: "+ password +" }";
|
||||
let credentials = '{ username: ' + username + ', password: ' + password + ' }';
|
||||
|
||||
var headers = new Headers();
|
||||
let headers = new Headers();
|
||||
headers.append('Content-Type', 'application/json');
|
||||
|
||||
return this.http.post(this._baseUrl+ 'login', credentials, {
|
||||
headers: headers
|
||||
})
|
||||
return this.http.post(this._baseUrl + 'login', credentials, {
|
||||
headers: headers
|
||||
})
|
||||
.map((res:any) => {
|
||||
let response = res.json();
|
||||
let response = res.json();
|
||||
this.token = response.data.ticket;
|
||||
this.saveJwt(this.token);
|
||||
})
|
||||
@@ -59,8 +59,8 @@ export class Authentication {
|
||||
}
|
||||
|
||||
saveJwt(jwt) {
|
||||
if(jwt) {
|
||||
localStorage.setItem('token', jwt)
|
||||
if (jwt) {
|
||||
localStorage.setItem('token', jwt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export class Authentication {
|
||||
return Observable.of(true);
|
||||
}
|
||||
|
||||
private handleError (error: Response) {
|
||||
private handleError(error:Response) {
|
||||
// in a real world app, we may send the error to some remote logging infrastructure
|
||||
// instead of just logging it to the console
|
||||
console.error(error);
|
||||
|
Reference in New Issue
Block a user