app refactoring
This commit is contained in:
parent
a3e2f252b7
commit
ff33395a5f
|
@ -10,7 +10,7 @@ import { Store, select } from '@ngrx/store';
|
|||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
|
||||
import { AuthenticationService } from '../services/authentication.service';
|
||||
import { AppAuthenticationService } from '../services/authentication.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -18,7 +18,7 @@ import { AuthenticationService } from '../services/authentication.service';
|
|||
export class AuthGuard implements CanActivate {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService
|
||||
private appAuthenticationService: AppAuthenticationService
|
||||
) {}
|
||||
|
||||
canActivate(
|
||||
|
@ -30,7 +30,7 @@ export class AuthGuard implements CanActivate {
|
|||
| Observable<boolean | UrlTree>
|
||||
| Promise<boolean | UrlTree> {
|
||||
return new Promise<boolean | UrlTree>((resolve, reject) => {
|
||||
if (this.authenticationService.authenticated()) {
|
||||
if (this.appAuthenticationService.authenticated()) {
|
||||
resolve(true);
|
||||
} else {
|
||||
this.router.navigateByUrl('/account/login');
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { finalize, delay } from 'rxjs/operators';
|
||||
import { LoaderService } from '../services/loader.service';
|
||||
import { AppLoaderService } from '../services/loader.service';
|
||||
|
||||
@Injectable()
|
||||
export class LoaderInterceptor implements HttpInterceptor {
|
||||
|
@ -22,13 +22,13 @@ export class LoaderInterceptor implements HttpInterceptor {
|
|||
}
|
||||
console.warn('LoaderInterceptor');
|
||||
|
||||
const loaderService = this.injector.get(LoaderService);
|
||||
const appLoaderService = this.injector.get(AppLoaderService);
|
||||
|
||||
loaderService.show();
|
||||
appLoaderService.show();
|
||||
|
||||
return next.handle(req).pipe(
|
||||
delay(3000),
|
||||
finalize(() => loaderService.hide())
|
||||
finalize(() => appLoaderService.hide())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,63 +1,13 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
||||
import {
|
||||
SVC_TYPE_LOGOUT,
|
||||
SSVC_TYPE_LOGOUT_RES,
|
||||
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
|
||||
AuthenticationProtocolService
|
||||
} from '@ucap-webmessenger/protocol-authentication';
|
||||
|
||||
import * as AuthenticationStore from '../store/account/authentication';
|
||||
import { AppNotificationService } from './notification.service';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
constructor(
|
||||
private protocolService: ProtocolService,
|
||||
private authenticationProtocolService: AuthenticationProtocolService,
|
||||
private store: Store<any>
|
||||
) {
|
||||
this.protocolService.serverMessage
|
||||
.pipe(
|
||||
filter(message => message.serviceType === SVC_TYPE_LOGOUT),
|
||||
filter(
|
||||
message =>
|
||||
message.subServiceType === SSVC_TYPE_LOGOUT_RES ||
|
||||
message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI
|
||||
),
|
||||
tap(message => {
|
||||
switch (message.subServiceType) {
|
||||
case SSVC_TYPE_LOGOUT_RES:
|
||||
{
|
||||
const logoutRes = this.authenticationProtocolService.decodeLogoutResponse(
|
||||
message
|
||||
);
|
||||
this.store.dispatch(AuthenticationStore.logout());
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_LOGOUT_REMOTE_NOTI:
|
||||
{
|
||||
const logoutRemoteNoti = this.authenticationProtocolService.decodeLogoutRemoteNotification(
|
||||
message
|
||||
);
|
||||
this.store.dispatch(AuthenticationStore.logout());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
constructor(private appNotificationService: AppNotificationService) {}
|
||||
|
||||
public postInit(): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.appNotificationService.subscribe();
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import { LoginInfo, KEY_LOGIN_INFO } from '../types';
|
|||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthenticationService {
|
||||
export class AppAuthenticationService {
|
||||
showLoader = false;
|
||||
|
||||
constructor(
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import { AppService } from './app.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { LoaderService } from './loader.service';
|
||||
import { AppAuthenticationService } from './authentication.service';
|
||||
import { AppLoaderService } from './loader.service';
|
||||
import { AppNotificationService } from './notification.service';
|
||||
|
||||
export const SERVICES = [AppService, AuthenticationService, LoaderService];
|
||||
export const SERVICES = [
|
||||
AppService,
|
||||
AppAuthenticationService,
|
||||
AppLoaderService,
|
||||
AppNotificationService
|
||||
];
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
|||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LoaderService {
|
||||
export class AppLoaderService {
|
||||
showLoader = false;
|
||||
|
||||
constructor() {}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
||||
import {
|
||||
SVC_TYPE_LOGOUT,
|
||||
SSVC_TYPE_LOGOUT_RES,
|
||||
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
|
||||
AuthenticationProtocolService
|
||||
} from '@ucap-webmessenger/protocol-authentication';
|
||||
|
||||
import * as AuthenticationStore from '../store/account/authentication';
|
||||
|
||||
@Injectable()
|
||||
export class AppNotificationService {
|
||||
constructor(
|
||||
private protocolService: ProtocolService,
|
||||
private authenticationProtocolService: AuthenticationProtocolService,
|
||||
private store: Store<any>
|
||||
) {}
|
||||
|
||||
public subscribe(): void {
|
||||
this.protocolService.serverMessage
|
||||
.pipe(
|
||||
filter(
|
||||
message =>
|
||||
message.serviceType === SVC_TYPE_LOGOUT &&
|
||||
message.subServiceType === SSVC_TYPE_LOGOUT_RES
|
||||
),
|
||||
tap(message => {
|
||||
const logoutRes = this.authenticationProtocolService.decodeLogoutResponse(
|
||||
message
|
||||
);
|
||||
console.log('logoutRes', logoutRes);
|
||||
this.store.dispatch(AuthenticationStore.logout());
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
|
||||
this.protocolService.serverMessage
|
||||
.pipe(
|
||||
filter(
|
||||
message =>
|
||||
message.serviceType === SVC_TYPE_LOGOUT &&
|
||||
message.subServiceType === SSVC_TYPE_LOGOUT_REMOTE_NOTI
|
||||
),
|
||||
tap(message => {
|
||||
const logoutRemoteNoti = this.authenticationProtocolService.decodeLogoutRemoteNotification(
|
||||
message
|
||||
);
|
||||
this.store.dispatch(AuthenticationStore.logout());
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ import {
|
|||
logoutConfirmationDismiss
|
||||
} from './actions';
|
||||
import { LoginInfo } from '../../../types';
|
||||
import { AuthenticationService } from '../../../services/authentication.service';
|
||||
import { AppAuthenticationService } from '../../../services/authentication.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
@ -73,7 +73,7 @@ export class Effects {
|
|||
take(1),
|
||||
map((update: boolean) => {
|
||||
if (!update) {
|
||||
this.authenticationService.login(
|
||||
this.appAuthenticationService.login(
|
||||
params.loginInfo,
|
||||
params.rememberMe
|
||||
);
|
||||
|
@ -104,7 +104,7 @@ export class Effects {
|
|||
ofType(logout),
|
||||
map(action => action),
|
||||
map(() => {
|
||||
this.authenticationService.logout();
|
||||
this.appAuthenticationService.logout();
|
||||
return loginRedirect();
|
||||
})
|
||||
)
|
||||
|
@ -136,7 +136,7 @@ export class Effects {
|
|||
private actions$: Actions,
|
||||
private router: Router,
|
||||
private piService: PiService,
|
||||
private authenticationService: AuthenticationService,
|
||||
private appAuthenticationService: AppAuthenticationService,
|
||||
private dialogService: DialogService,
|
||||
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
|
||||
) {}
|
||||
|
|
|
@ -8,8 +8,9 @@ import {
|
|||
// tslint:disable-next-line: no-empty-interface
|
||||
export interface LogoutRequest extends ProtocolRequest {}
|
||||
|
||||
// tslint:disable-next-line: no-empty-interface
|
||||
export interface LogoutResponse extends ProtocolResponse {}
|
||||
export interface LogoutResponse extends ProtocolResponse {
|
||||
reasonCode?: number;
|
||||
}
|
||||
|
||||
export interface LogoutRemoteRequest extends ProtocolRequest {
|
||||
targetDeviceType?: DeviceType;
|
||||
|
|
|
@ -121,7 +121,9 @@ export class AuthenticationProtocolService {
|
|||
}
|
||||
|
||||
public decodeLogoutResponse(message: ServerMessage): LogoutResponse {
|
||||
return {} as LogoutResponse;
|
||||
return {
|
||||
reasonCode: message.bodyList[0]
|
||||
} as LogoutResponse;
|
||||
}
|
||||
|
||||
public logoutRemote(
|
||||
|
|
Loading…
Reference in New Issue
Block a user