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 { Observable } from 'rxjs';
|
||||||
import { map, take } from 'rxjs/operators';
|
import { map, take } from 'rxjs/operators';
|
||||||
|
|
||||||
import { AuthenticationService } from '../services/authentication.service';
|
import { AppAuthenticationService } from '../services/authentication.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -18,7 +18,7 @@ import { AuthenticationService } from '../services/authentication.service';
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private authenticationService: AuthenticationService
|
private appAuthenticationService: AppAuthenticationService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
canActivate(
|
canActivate(
|
||||||
|
@ -30,7 +30,7 @@ export class AuthGuard implements CanActivate {
|
||||||
| Observable<boolean | UrlTree>
|
| Observable<boolean | UrlTree>
|
||||||
| Promise<boolean | UrlTree> {
|
| Promise<boolean | UrlTree> {
|
||||||
return new Promise<boolean | UrlTree>((resolve, reject) => {
|
return new Promise<boolean | UrlTree>((resolve, reject) => {
|
||||||
if (this.authenticationService.authenticated()) {
|
if (this.appAuthenticationService.authenticated()) {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
this.router.navigateByUrl('/account/login');
|
this.router.navigateByUrl('/account/login');
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { finalize, delay } from 'rxjs/operators';
|
import { finalize, delay } from 'rxjs/operators';
|
||||||
import { LoaderService } from '../services/loader.service';
|
import { AppLoaderService } from '../services/loader.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LoaderInterceptor implements HttpInterceptor {
|
export class LoaderInterceptor implements HttpInterceptor {
|
||||||
|
@ -22,13 +22,13 @@ export class LoaderInterceptor implements HttpInterceptor {
|
||||||
}
|
}
|
||||||
console.warn('LoaderInterceptor');
|
console.warn('LoaderInterceptor');
|
||||||
|
|
||||||
const loaderService = this.injector.get(LoaderService);
|
const appLoaderService = this.injector.get(AppLoaderService);
|
||||||
|
|
||||||
loaderService.show();
|
appLoaderService.show();
|
||||||
|
|
||||||
return next.handle(req).pipe(
|
return next.handle(req).pipe(
|
||||||
delay(3000),
|
delay(3000),
|
||||||
finalize(() => loaderService.hide())
|
finalize(() => appLoaderService.hide())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +1,13 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { AppNotificationService } from './notification.service';
|
||||||
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()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
constructor(
|
constructor(private appNotificationService: AppNotificationService) {}
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public postInit(): Promise<void> {
|
public postInit(): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
this.appNotificationService.subscribe();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { LoginInfo, KEY_LOGIN_INFO } from '../types';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthenticationService {
|
export class AppAuthenticationService {
|
||||||
showLoader = false;
|
showLoader = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { AuthenticationService } from './authentication.service';
|
import { AppAuthenticationService } from './authentication.service';
|
||||||
import { LoaderService } from './loader.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({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class LoaderService {
|
export class AppLoaderService {
|
||||||
showLoader = false;
|
showLoader = false;
|
||||||
|
|
||||||
constructor() {}
|
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
|
logoutConfirmationDismiss
|
||||||
} from './actions';
|
} from './actions';
|
||||||
import { LoginInfo } from '../../../types';
|
import { LoginInfo } from '../../../types';
|
||||||
import { AuthenticationService } from '../../../services/authentication.service';
|
import { AppAuthenticationService } from '../../../services/authentication.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Effects {
|
export class Effects {
|
||||||
|
@ -73,7 +73,7 @@ export class Effects {
|
||||||
take(1),
|
take(1),
|
||||||
map((update: boolean) => {
|
map((update: boolean) => {
|
||||||
if (!update) {
|
if (!update) {
|
||||||
this.authenticationService.login(
|
this.appAuthenticationService.login(
|
||||||
params.loginInfo,
|
params.loginInfo,
|
||||||
params.rememberMe
|
params.rememberMe
|
||||||
);
|
);
|
||||||
|
@ -104,7 +104,7 @@ export class Effects {
|
||||||
ofType(logout),
|
ofType(logout),
|
||||||
map(action => action),
|
map(action => action),
|
||||||
map(() => {
|
map(() => {
|
||||||
this.authenticationService.logout();
|
this.appAuthenticationService.logout();
|
||||||
return loginRedirect();
|
return loginRedirect();
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -136,7 +136,7 @@ export class Effects {
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private piService: PiService,
|
private piService: PiService,
|
||||||
private authenticationService: AuthenticationService,
|
private appAuthenticationService: AppAuthenticationService,
|
||||||
private dialogService: DialogService,
|
private dialogService: DialogService,
|
||||||
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
|
||||||
) {}
|
) {}
|
||||||
|
|
|
@ -8,8 +8,9 @@ import {
|
||||||
// tslint:disable-next-line: no-empty-interface
|
// tslint:disable-next-line: no-empty-interface
|
||||||
export interface LogoutRequest extends ProtocolRequest {}
|
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 {
|
export interface LogoutRemoteRequest extends ProtocolRequest {
|
||||||
targetDeviceType?: DeviceType;
|
targetDeviceType?: DeviceType;
|
||||||
|
|
|
@ -121,7 +121,9 @@ export class AuthenticationProtocolService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public decodeLogoutResponse(message: ServerMessage): LogoutResponse {
|
public decodeLogoutResponse(message: ServerMessage): LogoutResponse {
|
||||||
return {} as LogoutResponse;
|
return {
|
||||||
|
reasonCode: message.bodyList[0]
|
||||||
|
} as LogoutResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public logoutRemote(
|
public logoutRemote(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user