separation login from constructor JS-API

This commit is contained in:
Eugenio Romano
2016-08-17 12:04:29 +01:00
parent dc19e45e7b
commit b5ffa6fd36

View File

@@ -34,6 +34,12 @@ export class AlfrescoAuthenticationService {
* @param alfrescoSetting * @param alfrescoSetting
*/ */
constructor(public alfrescoSetting: AlfrescoSettingsService) { constructor(public alfrescoSetting: AlfrescoSettingsService) {
this.alfrescoApi = new AlfrescoApi({
provider: this.alfrescoSetting.getProviders(),
ticket: this.isLoggedIn() ? this.getTicket() : null,
host: this.alfrescoSetting.ecmHost,
hostActiviti: this.alfrescoSetting.bpmHost
});
} }
/** /**
@@ -53,18 +59,10 @@ export class AlfrescoAuthenticationService {
login(username: string, password: string) { login(username: string, password: string) {
if (this.isLoggedIn()) { if (this.isLoggedIn()) {
this.alfrescoApi = new AlfrescoApi({
provider: this.alfrescoSetting.getProviders(),
ticket: this.getTicket(),
host: this.alfrescoSetting.ecmHost,
hostActiviti: this.alfrescoSetting.bpmHost
});
return Observable.create((observer) => { return Observable.create((observer) => {
observer.next({type: this.alfrescoSetting.getProviders(), ticket: this.getTicket()}); observer.next({type: this.alfrescoSetting.getProviders(), ticket: this.getTicket()});
observer.complete(); observer.complete();
}).catch(this.handleError); }).catch(this.handleError);
} else { } else {
return Observable.fromPromise(this.callApiLogin(username, password)) return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => { .map((response: any) => {
@@ -82,16 +80,7 @@ export class AlfrescoAuthenticationService {
* @returns {*|Observable<any>} * @returns {*|Observable<any>}
*/ */
private callApiLogin(username: string, password: string) { private callApiLogin(username: string, password: string) {
return this.alfrescoApi.login(username, password);
this.alfrescoApi = new AlfrescoApi({
provider: this.alfrescoSetting.getProviders(),
username: username,
password: password,
host: this.alfrescoSetting.ecmHost,
hostActiviti: this.alfrescoSetting.bpmHost
});
return this.alfrescoApi.login();
} }
/** /**