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