mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
auth service api improvements (#1865)
Rename Auth Service events: - loginSubject -> onLogin - logoutSubject -> onLogout
This commit is contained in:
parent
4db98a1d7b
commit
130c2e4428
@ -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';
|
||||
|
@ -24,8 +24,9 @@ import { AlfrescoApiService } from './alfresco-api.service';
|
||||
|
||||
@Injectable()
|
||||
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,
|
||||
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 => <any> res)
|
||||
.do(response => {
|
||||
this.removeTicket();
|
||||
this.logoutSubject.next(response);
|
||||
this.onLogout.next(response);
|
||||
return response;
|
||||
})
|
||||
.catch(err => this.handleError(err));
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user