mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Fix token problem
This commit is contained in:
@@ -83,8 +83,8 @@ export class MyDemoApp implements OnInit {
|
||||
constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) {
|
||||
alfrescoSettingsService.host = this.host;
|
||||
|
||||
if (localStorage.getItem('token')) {
|
||||
this.token = localStorage.getItem('token');
|
||||
if (this.authService.getToken()) {
|
||||
this.token = this.authService.getToken();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,15 +18,16 @@
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { FileModel } from '../models/file.model';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
|
||||
export class UploadServiceMock extends UploadService {
|
||||
|
||||
filesUpload$: Observable<any>;
|
||||
totalCompleted$: Observable<number>;
|
||||
|
||||
constructor(settings: AlfrescoSettingsService) {
|
||||
super(settings);
|
||||
constructor(settings: AlfrescoSettingsService,
|
||||
authService: AlfrescoAuthenticationService) {
|
||||
super(settings, authService);
|
||||
}
|
||||
|
||||
public setOptions(options: any): void {
|
||||
|
@@ -19,7 +19,7 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
|
||||
import { FileModel } from '../models/file.model';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadServiceMock } from '../assets/upload.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
@@ -33,6 +33,7 @@ describe('FileUploadDialog', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsService },
|
||||
{ provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
{ provide: UploadService, useClass: UploadServiceMock }
|
||||
];
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadServiceMock } from '../assets/upload.service.mock';
|
||||
import { UploadService } from '../services/upload.service';
|
||||
@@ -39,6 +39,7 @@ describe('AlfrescoUploadButton', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock },
|
||||
{ provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
{ provide: UploadService, useClass: UploadServiceMock }
|
||||
];
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock';
|
||||
import { TranslationMock } from '../assets/translation.service.mock';
|
||||
import { UploadServiceMock } from '../assets/upload.service.mock';
|
||||
@@ -38,6 +38,7 @@ describe('AlfrescoUploadDragArea', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock },
|
||||
{ provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService },
|
||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||
{ provide: UploadService, useClass: UploadServiceMock }
|
||||
];
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { UploadService } from './upload.service';
|
||||
import { FileModel } from './../models/file.model';
|
||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock';
|
||||
import { AlfrescoApiMock } from '../assets/AlfrescoApi.mock';
|
||||
|
||||
@@ -30,8 +30,9 @@ let errorFn = jasmine.createSpy('error');
|
||||
|
||||
class MockUploadService extends UploadService {
|
||||
|
||||
constructor(settings: AlfrescoSettingsService) {
|
||||
super(settings);
|
||||
constructor(settings: AlfrescoSettingsService,
|
||||
authService: AlfrescoAuthenticationService) {
|
||||
super(settings, authService);
|
||||
}
|
||||
|
||||
createXMLHttpRequestInstance() {
|
||||
@@ -66,6 +67,7 @@ describe('AlfrescoUploadService', () => {
|
||||
beforeEachProviders(() => {
|
||||
return [
|
||||
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock },
|
||||
{ provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService },
|
||||
{ provide: UploadService, useClass: MockUploadService }
|
||||
];
|
||||
});
|
||||
|
@@ -20,7 +20,7 @@ import { EventEmitter, Injectable } from '@angular/core';
|
||||
import { Response } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { FileModel } from '../models/file.model';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
@@ -50,7 +50,8 @@ export class UploadService {
|
||||
|
||||
public totalCompleted: number = 0;
|
||||
|
||||
constructor(private settings: AlfrescoSettingsService) {
|
||||
constructor(private settings: AlfrescoSettingsService,
|
||||
private authService: AlfrescoAuthenticationService) {
|
||||
console.log('UploadService constructor');
|
||||
this.filesUpload$ = new Observable<FileModel[]>(observer => this._filesUploadObserver = observer).share();
|
||||
this.totalCompleted$ = new Observable<number>(observer => this._totalCompletedObserver = observer).share();
|
||||
@@ -92,20 +93,12 @@ export class UploadService {
|
||||
return this._formFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token from the local storage
|
||||
* @returns {any}
|
||||
*/
|
||||
private getAlfrescoTicket(): string {
|
||||
return localStorage.getItem('token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the alfresco client
|
||||
* @returns {AlfrescoApi.ApiClient}
|
||||
*/
|
||||
private getAlfrescoClient() {
|
||||
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.getAlfrescoTicket());
|
||||
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user