From 130c2e4428564a55649db55ce368a891572e7b9f Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Sat, 13 May 2017 01:05:01 +0100 Subject: [PATCH] auth service api improvements (#1865) Rename Auth Service events: - loginSubject -> onLogin - logoutSubject -> onLogout --- ng2-components/ng2-alfresco-core/README.md | 7 +++++++ .../src/services/alfresco-authentication.service.ts | 10 +++++----- .../src/components/user-info.component.ts | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ng2-components/ng2-alfresco-core/README.md b/ng2-components/ng2-alfresco-core/README.md index 1f9a408051..cb3d7fb468 100644 --- a/ng2-components/ng2-alfresco-core/README.md +++ b/ng2-components/ng2-alfresco-core/README.md @@ -331,6 +331,13 @@ export class MyComponent implements OnInit { The authentication service is used inside the [login component](../ng2-alfresco-login) and is possible to find there an example of how to use it. +### Events + +| Name | Description | +| --- | --- | +| onLogin | Raised when user logs in | +| onLogout | Raised when user logs out | + ```ts import { NgModule, Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; diff --git a/ng2-components/ng2-alfresco-core/src/services/alfresco-authentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/alfresco-authentication.service.ts index 0bf11793aa..2ca469958b 100644 --- a/ng2-components/ng2-alfresco-core/src/services/alfresco-authentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/alfresco-authentication.service.ts @@ -24,8 +24,9 @@ import { AlfrescoApiService } from './alfresco-api.service'; @Injectable() export class AlfrescoAuthenticationService { - loginSubject: Subject = new Subject(); - logoutSubject: Subject = new Subject(); + + onLogin: Subject = new Subject(); + onLogout: Subject = new Subject(); constructor(private settingsService: AlfrescoSettingsService, public alfrescoApi: AlfrescoApiService, @@ -52,7 +53,7 @@ export class AlfrescoAuthenticationService { return Observable.fromPromise(this.callApiLogin(username, password)) .map((response: any) => { this.saveTickets(); - this.loginSubject.next(response); + this.onLogin.next(response); return {type: this.settingsService.getProviders(), ticket: response}; }) .catch(err => this.handleError(err)); @@ -75,10 +76,9 @@ export class AlfrescoAuthenticationService { */ logout() { return Observable.fromPromise(this.callApiLogout()) - .map(res => res) .do(response => { this.removeTicket(); - this.logoutSubject.next(response); + this.onLogout.next(response); return response; }) .catch(err => this.handleError(err)); diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts index 7dadf39f03..fc51f3142d 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts @@ -56,7 +56,7 @@ export class UserInfoComponent implements OnInit { if (translateService) { translateService.addTranslationFolder('ng2-alfresco-userinfo', 'node_modules/ng2-alfresco-userinfo/src'); } - authService.loginSubject.subscribe((response) => { + authService.onLogin.subscribe((response) => { this.getUserInfo(); }); }