This commit is contained in:
Eugenio Romano 2016-09-05 16:10:59 +02:00
parent 530ca19b1d
commit 8dfef264e3

View File

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
import {Component, OnInit, Input} from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import {bootstrap} from '@angular/platform-browser-dynamic'; import { bootstrap } from '@angular/platform-browser-dynamic';
import {HTTP_PROVIDERS} from '@angular/http'; import { HTTP_PROVIDERS } from '@angular/http';
import { import {
ALFRESCO_CORE_PROVIDERS, ALFRESCO_CORE_PROVIDERS,
@ -26,17 +26,17 @@ import {
CONTEXT_MENU_DIRECTIVES CONTEXT_MENU_DIRECTIVES
} from 'ng2-alfresco-core'; } from 'ng2-alfresco-core';
import {TAGCOMPONENT, TAGSERVICES} from 'ng2-alfresco-tag'; import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag';
@Component({ @Component({
selector: 'alfresco-tag-demo', selector: 'alfresco-tag-demo',
template: ` template: `
<label for="token"><b>Insert a valid access token / ticket:</b></label><br> <label for="ticket"><b>Insert a valid access ticket / ticket:</b></label><br>
<input id="token" type="text" size="48" (change)="updateToken();documentList.reload()" [(ngModel)]="token"><br> <input id="ticket" type="text" size="48" (change)="updateTicket()" [(ngModel)]="ticket"><br>
<label for="host"><b>Insert the ip of your Alfresco instance:</b></label><br> <label for="host"><b>Insert the ip of your Alfresco instance:</b></label><br>
<input id="host" type="text" size="48" (change)="updateHost();documentList.reload()" [(ngModel)]="ecmHost"><br><br> <input id="host" type="text" size="48" (change)="updateHost()" [(ngModel)]="ecmHost"><br><br>
<div *ngIf="!authenticated" style="color:#FF2323"> <div *ngIf="!authenticated" style="color:#FF2323">
Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid token to perform Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid ticket to perform
operations. operations.
</div> </div>
<hr> <hr>
@ -73,24 +73,17 @@ class TagDemo implements OnInit {
ecmHost: string = 'http://127.0.0.1:8080'; ecmHost: string = 'http://127.0.0.1:8080';
token: string; ticket: string;
constructor(private authService: AlfrescoAuthenticationService, constructor(private authService: AlfrescoAuthenticationService,
private settingsService: AlfrescoSettingsService) { private settingsService: AlfrescoSettingsService) {
settingsService.ecmHost = this.ecmHost; settingsService.ecmHost = this.ecmHost;
if (this.authService.getTicket()) { settingsService.setProviders('ECM');
this.token = this.authService.getTicket();
}
}
public updateToken(): void { if (this.authService.getTicketEcm()) {
localStorage.setItem('token', this.token); this.ticket = this.authService.getTicketEcm();
} }
public updateHost(): void {
this.settingsService.ecmHost = this.ecmHost;
this.login();
} }
ngOnInit() { ngOnInit() {
@ -98,10 +91,10 @@ class TagDemo implements OnInit {
} }
login() { login() {
this.authService.login('admin', 'admin', ['ECM']).subscribe( this.authService.login('admin', 'admin').subscribe(
token => { ticket => {
console.log(token); console.log(ticket);
this.token = token; this.ticket = this.authService.getTicketEcm();
this.authenticated = true; this.authenticated = true;
}, },
error => { error => {
@ -110,11 +103,19 @@ class TagDemo implements OnInit {
}); });
} }
public updateTicket(): void {
localStorage.setItem('ticket-ECM', this.ticket);
}
public updateHost(): void {
this.settingsService.ecmHost = this.ecmHost;
this.login();
}
logData(data) { logData(data) {
console.log(data); console.log(data);
} }
} }
bootstrap(TagDemo, [ bootstrap(TagDemo, [
HTTP_PROVIDERS, HTTP_PROVIDERS,
ALFRESCO_CORE_PROVIDERS ALFRESCO_CORE_PROVIDERS