mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Document List demo using core auth, fix auth service issues
This commit is contained in:
parent
8f99565991
commit
7f7385de1a
@ -75,6 +75,7 @@ export class AlfrescoAuthenticationService {
|
|||||||
let response = res.json();
|
let response = res.json();
|
||||||
this.token = response.entry.id;
|
this.token = response.entry.id;
|
||||||
this.saveJwt(this.token);
|
this.saveJwt(this.token);
|
||||||
|
return this.token;
|
||||||
})
|
})
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,14 @@
|
|||||||
|
|
||||||
import { Component, OnInit } from 'angular2/core';
|
import { Component, OnInit } from 'angular2/core';
|
||||||
import { bootstrap } from 'angular2/platform/browser';
|
import { bootstrap } from 'angular2/platform/browser';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { HTTP_PROVIDERS } from 'angular2/http';
|
||||||
import { HTTP_PROVIDERS, Http, Headers, Response } from 'angular2/http';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ALFRESCO_CORE_PROVIDERS,
|
ALFRESCO_CORE_PROVIDERS,
|
||||||
AlfrescoSettingsService
|
AlfrescoSettingsService,
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoPipeTranslate,
|
||||||
|
AlfrescoTranslationService
|
||||||
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -30,8 +32,6 @@ import {
|
|||||||
DOCUMENT_LIST_PROVIDERS,
|
DOCUMENT_LIST_PROVIDERS,
|
||||||
DocumentActionsService
|
DocumentActionsService
|
||||||
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
|
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
|
||||||
import { AlfrescoPipeTranslate, AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'alfresco-documentlist-demo',
|
selector: 'alfresco-documentlist-demo',
|
||||||
@ -120,7 +120,7 @@ class DocumentListDemo implements OnInit {
|
|||||||
authenticated: boolean;
|
authenticated: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: Http,
|
private authService: AlfrescoAuthenticationService,
|
||||||
settings: AlfrescoSettingsService,
|
settings: AlfrescoSettingsService,
|
||||||
translation: AlfrescoTranslationService,
|
translation: AlfrescoTranslationService,
|
||||||
documentActions: DocumentActionsService) {
|
documentActions: DocumentActionsService) {
|
||||||
@ -147,26 +147,9 @@ class DocumentListDemo implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
let host = 'http://192.168.99.100:8080';
|
this.authService.login('admin', 'admin').subscribe(token => {
|
||||||
let credentials = { 'userId': 'admin', 'password': 'admin' };
|
this.authenticated = true;
|
||||||
let url = `${host}/alfresco/api/-default-/public/authentication/versions/1/tickets`;
|
});
|
||||||
|
|
||||||
let headers = new Headers();
|
|
||||||
headers.append('Content-Type', 'application/json');
|
|
||||||
headers.append('Accept', 'application/json');
|
|
||||||
|
|
||||||
this.http.post(url, JSON.stringify(credentials), { headers: headers })
|
|
||||||
.map(res => res.json().entry.id)
|
|
||||||
.catch(this.handleError)
|
|
||||||
.subscribe(token => {
|
|
||||||
localStorage.setItem('token', token);
|
|
||||||
this.authenticated = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleError(error: Response) {
|
|
||||||
console.error('Error when logging in', error);
|
|
||||||
return Observable.throw(error.json().message || 'Server error');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user