diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index 9d25072986..c91adc4258 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -21,6 +21,8 @@ import { AlfrescoSettingsService } from './AlfrescoSettings.service'; import { AlfrescoApiService } from './AlfrescoApi.service'; import * as alfrescoApi from 'alfresco-js-api'; import { AlfrescoApi } from 'alfresco-js-api'; +import { Subject } from 'rxjs/Subject'; + /** * The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage */ @@ -29,6 +31,10 @@ export class AlfrescoAuthenticationService { alfrescoApi: AlfrescoApi; + public loginSubject: Subject = new Subject(); + + public logoutSubject: Subject = new Subject(); + /** * Constructor * @param settingsService @@ -84,6 +90,7 @@ export class AlfrescoAuthenticationService { return Observable.fromPromise(this.callApiLogin(username, password)) .map((response: any) => { this.saveTickets(); + this.loginSubject.next(response); return {type: this.settingsService.getProviders(), ticket: response}; }) .catch(this.handleError); @@ -109,6 +116,7 @@ export class AlfrescoAuthenticationService { return Observable.fromPromise(this.callApiLogout()) .map(res => res) .do(response => { + this.logoutSubject.next(response); return response; }) .catch(this.handleError); diff --git a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts index 68224a8190..a0eee66354 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts @@ -20,54 +20,53 @@ import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { UserInfoComponentModule } from 'ng2-alfresco-userinfo'; import { CoreModule } from 'ng2-alfresco-core'; -import { LoginModule } from 'ng2-alfresco-login'; +import { LoginModule } from 'ng2-alfresco-login'; import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; @Component({ selector: 'alfresco-app-demo', - template: ` -
- ECM Host:
- BPM Host:
-
- -

- -

-

- -

-

- -

-

- -

-
- {{ status }} -
- - -
- + template: ` +
+ ECM Host:
+ BPM Host:
+
+ +

+ +

+

+ +

+

+ +

+

+ +

+
+ {{ status }} +
+ + +
+
- - - - `, + + + `, styles: [ ':host > .container {padding: 10px}', '.p-10 { padding: 10px; }' @@ -75,93 +74,93 @@ import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfr }) class UserInfoDemo implements OnInit { - public ecmHost: string = 'http://localhost:8080'; - - public bpmHost: string = 'http://localhost:9999'; - - public userToLogin: string = 'admin'; - - public password: string = 'admin'; - - public loginErrorMessage: string; - - public providers: string = 'BPM'; - - private authenticated: boolean; + public ecmHost: string = 'http://localhost:8080'; - private token: any; + public bpmHost: string = 'http://localhost:9999'; - public disableCsrf: boolean = false; - - constructor(private authService: AlfrescoAuthenticationService, - private settingsService: AlfrescoSettingsService) { - settingsService.ecmHost = this.ecmHost; - settingsService.bpmHost = this.bpmHost; - } - - ngOnInit() { - this.settingsService.setProviders(this.providers); - } - - logout() { - this.authService.logout(); - } - - login(user, password) { + public userToLogin: string = 'admin'; + + public password: string = 'admin'; + + public loginErrorMessage: string; + + public providers: string = 'BPM'; + + private authenticated: boolean; + + private token: any; + + public disableCsrf: boolean = false; + + constructor(private authService: AlfrescoAuthenticationService, + private settingsService: AlfrescoSettingsService) { + settingsService.ecmHost = this.ecmHost; + settingsService.bpmHost = this.bpmHost; + } + + ngOnInit() { this.settingsService.setProviders(this.providers); - this.authService.login(user, password).subscribe( - token => { - console.log(token); - this.token = token; - this.authenticated = true; - }, - error => { - console.log(error); - this.authenticated = false; - this.loginErrorMessage = error; - }); - } + } - isLoggedIn(): boolean { - return this.authService.isLoggedIn(); - } - - toggleECM(checked) { - if (checked && this.providers === 'BPM') { - this.providers = 'ALL'; - } else if (checked) { - this.providers = 'ECM'; - } else { - this.providers = undefined; - } - } - - toggleBPM(checked) { - if (checked && this.providers === 'ECM') { - this.providers = 'ALL'; - } else if (checked) { - this.providers = 'BPM'; - } else { - this.providers = undefined; - } - } - - toggleCSRF() { - this.disableCsrf = !this.disableCsrf; - } + logout() { + this.authService.logout(); + } + + login(user, password) { + this.settingsService.setProviders(this.providers); + this.authService.login(user, password).subscribe( + token => { + console.log(token); + this.token = token; + this.authenticated = true; + }, + error => { + console.log(error); + this.authenticated = false; + this.loginErrorMessage = error; + }); + } + + isLoggedIn(): boolean { + return this.authService.isLoggedIn(); + } + + toggleECM(checked) { + if (checked && this.providers === 'BPM') { + this.providers = 'ALL'; + } else if (checked) { + this.providers = 'ECM'; + } else { + this.providers = undefined; + } + } + + toggleBPM(checked) { + if (checked && this.providers === 'ECM') { + this.providers = 'ALL'; + } else if (checked) { + this.providers = 'BPM'; + } else { + this.providers = undefined; + } + } + + toggleCSRF() { + this.disableCsrf = !this.disableCsrf; + } } @NgModule({ imports: [ BrowserModule, CoreModule.forRoot(), - UserInfoComponentModule.forRoot(), - LoginModule + UserInfoComponentModule.forRoot(), + LoginModule ], - declarations: [UserInfoDemo], - bootstrap: [UserInfoDemo] + declarations: [UserInfoDemo], + bootstrap: [UserInfoDemo] }) -export class AppModule { -} +export class AppModule { +} platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html index 394c9aac6f..753230730e 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.html @@ -1,4 +1,4 @@ -
+
{ + this.getUserInfo(); + }); } ngAfterViewChecked() { @@ -69,10 +77,18 @@ export class UserInfoComponent implements AfterViewChecked, OnInit { } ngOnInit() { + this.getUserInfo(); + } + + getUserInfo() { this.getEcmUserInfo(); this.getBpmUserInfo(); } + isLoggedIn() { + return this.authService.isLoggedIn(); + } + getEcmUserInfo(): void { if (this.authService.isEcmLoggedIn()) { this.ecmUserService.getCurrentUserInfo()