diff --git a/ng2-components/ng2-alfresco-upload/README.md b/ng2-components/ng2-alfresco-upload/README.md
index 9a1b665df3..cf18d54aca 100644
--- a/ng2-components/ng2-alfresco-upload/README.md
+++ b/ng2-components/ng2-alfresco-upload/README.md
@@ -109,7 +109,7 @@ import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/d
template: `
`,
directives: [ALFRESCO_ULPOAD_COMPONENT]
diff --git a/ng2-components/ng2-alfresco-upload/demo/src/main.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts
index 5247807318..d73a1b15c9 100644
--- a/ng2-components/ng2-alfresco-upload/demo/src/main.ts
+++ b/ng2-components/ng2-alfresco-upload/demo/src/main.ts
@@ -15,17 +15,28 @@
* limitations under the License.
*/
-import { Component } from 'angular2/core';
+import { Component, OnInit } from 'angular2/core';
import { bootstrap } from 'angular2/platform/browser';
import { HTTP_PROVIDERS } from 'angular2/http';
-import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
+import {
+ ALFRESCO_CORE_PROVIDERS,
+ AlfrescoSettingsService,
+ AlfrescoAuthenticationService
+} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
@Component({
selector: 'my-app',
- template: `
-
+ template: `
+
+
+
+
+ Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid token to perform
+ operations.
+
+
- `,
+
+ `,
directives: [ALFRESCO_ULPOAD_COMPONENTS]
})
-export class MyDemoApp {
+export class MyDemoApp implements OnInit {
+
+ authenticated: boolean;
+
+ host: string = 'http://192.168.99.101:8080';
+
token: string;
- constructor(alfrescoSettingsService: AlfrescoSettingsService) {
- alfrescoSettingsService.host = 'http://192.168.99.100:8080';
+ constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) {
+ alfrescoSettingsService.host = this.host;
if (localStorage.getItem('token')) {
this.token = localStorage.getItem('token');
}
}
- updateToken() {
+ public updateToken(): void {
localStorage.setItem('token', this.token);
}
+ public updateHost(): void {
+ this.alfrescoSettingsService.host = this.host;
+ }
+
public customMethod(event: Object): void {
console.log('File uploaded');
}
+
+ public ngOnInit(): void {
+ this.login();
+ }
+
+ public login(): void {
+ this.authService.login('admin', 'admin').subscribe(token => {
+ this.authenticated = true;
+ });
+ }
}
bootstrap(MyDemoApp, [
HTTP_PROVIDERS,
- AlfrescoTranslationService,
- AlfrescoTranslationLoader,
- AlfrescoSettingsService,
+ ALFRESCO_CORE_PROVIDERS,
UploadService
]);
diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts
index 95ef3bfa70..40ffd0c2aa 100644
--- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts
+++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts
@@ -33,7 +33,6 @@ declare let AlfrescoApi: any;
*/
@Injectable()
export class UploadService {
- private _host: string = '';
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
private _url: string = '/alfresco/service/api/upload';
@@ -51,7 +50,6 @@ export class UploadService {
constructor(private settings: AlfrescoSettingsService) {
console.log('UploadService constructor');
this.filesUpload$ = new Observable(observer => this._filesUploadObserver = observer).share();
- this._host = settings.host;
this._alfrescoClient = this.getAlfrescoClient();
}
@@ -72,7 +70,7 @@ export class UploadService {
* @returns {string}
*/
public getHost(): string {
- return this._host;
+ return this.settings.host;
}
/**
@@ -220,7 +218,7 @@ export class UploadService {
let xmlHttpRequest = this.createXMLHttpRequestInstance(uploadingFileModel, elementEmit);
uploadingFileModel._xmlHttpRequest = xmlHttpRequest;
- xmlHttpRequest.open(this._method, this._host + this._url, true);
+ xmlHttpRequest.open(this._method, this.getHost() + this._url, true);
let authToken = btoa(basicAuth.username + ':' + basicAuth.password);
if (authToken) {
xmlHttpRequest.setRequestHeader('Authorization', `${basicAuth.type} ${authToken}`);