auth service api improvements (#1865)

Rename Auth Service events:
- loginSubject -> onLogin
- logoutSubject -> onLogout
This commit is contained in:
Denys Vuika 2017-05-13 01:05:01 +01:00 committed by Eugenio Romano
parent 4db98a1d7b
commit 130c2e4428
3 changed files with 13 additions and 6 deletions

View File

@ -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. 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 ```ts
import { NgModule, Component } from '@angular/core'; import { NgModule, Component } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';

View File

@ -24,8 +24,9 @@ import { AlfrescoApiService } from './alfresco-api.service';
@Injectable() @Injectable()
export class AlfrescoAuthenticationService { export class AlfrescoAuthenticationService {
loginSubject: Subject<any> = new Subject<any>();
logoutSubject: Subject<any> = new Subject<any>(); onLogin: Subject<any> = new Subject<any>();
onLogout: Subject<any> = new Subject<any>();
constructor(private settingsService: AlfrescoSettingsService, constructor(private settingsService: AlfrescoSettingsService,
public alfrescoApi: AlfrescoApiService, public alfrescoApi: AlfrescoApiService,
@ -52,7 +53,7 @@ export class AlfrescoAuthenticationService {
return Observable.fromPromise(this.callApiLogin(username, password)) return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => { .map((response: any) => {
this.saveTickets(); this.saveTickets();
this.loginSubject.next(response); this.onLogin.next(response);
return {type: this.settingsService.getProviders(), ticket: response}; return {type: this.settingsService.getProviders(), ticket: response};
}) })
.catch(err => this.handleError(err)); .catch(err => this.handleError(err));
@ -75,10 +76,9 @@ export class AlfrescoAuthenticationService {
*/ */
logout() { logout() {
return Observable.fromPromise(this.callApiLogout()) return Observable.fromPromise(this.callApiLogout())
.map(res => <any> res)
.do(response => { .do(response => {
this.removeTicket(); this.removeTicket();
this.logoutSubject.next(response); this.onLogout.next(response);
return response; return response;
}) })
.catch(err => this.handleError(err)); .catch(err => this.handleError(err));

View File

@ -56,7 +56,7 @@ export class UserInfoComponent implements OnInit {
if (translateService) { if (translateService) {
translateService.addTranslationFolder('ng2-alfresco-userinfo', 'node_modules/ng2-alfresco-userinfo/src'); translateService.addTranslationFolder('ng2-alfresco-userinfo', 'node_modules/ng2-alfresco-userinfo/src');
} }
authService.loginSubject.subscribe((response) => { authService.onLogin.subscribe((response) => {
this.getUserInfo(); this.getUserInfo();
}); });
} }