From 81c3cbe43ad65e587a002e5964de9a59139e03cb Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 19 Nov 2019 18:43:49 +0900 Subject: [PATCH] initialization of logout is modified --- .../store/account/authentication/actions.ts | 4 ++ .../store/account/authentication/effects.ts | 40 +++++++++++++------ .../store/account/authentication/reducers.ts | 11 ++++- .../src/app/store/messenger/chat/reducers.ts | 8 ++++ .../src/app/store/messenger/event/reducers.ts | 5 ++- .../app/store/messenger/option/reducers.ts | 2 +- .../src/app/store/messenger/query/reducers.ts | 2 +- .../src/app/store/messenger/room/reducers.ts | 5 ++- .../app/store/messenger/status/reducers.ts | 2 +- .../src/app/store/messenger/sync/reducers.ts | 8 ++++ .../src/app/store/setting/company/reducers.ts | 9 +++++ .../store/setting/version-info/reducers.ts | 8 ++++ 12 files changed, 84 insertions(+), 20 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts index b7b9849c..ec4aa37f 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/actions.ts @@ -66,6 +66,10 @@ export const logoutConfirmationDismiss = createAction( '[Account::Authentication] Logout Confirmation Dismiss' ); +export const logoutInitialize = createAction( + '[Account::Authentication] Logout Initialize' +); + export const postLogin = createAction( '[Account::Authentication] Post Login', props<{ diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts index 331398e1..90100265 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/effects.ts @@ -1,4 +1,4 @@ -import { Injectable, Inject } from '@angular/core'; +import { Injectable, Inject, NgZone } from '@angular/core'; import { Router } from '@angular/router'; import { of, Observable } from 'rxjs'; @@ -36,7 +36,8 @@ import { changePasswordFailure, changePasswordSuccess, increaseLoginFailCount, - initialLoginFailCount + initialLoginFailCount, + logoutInitialize } from './actions'; import { LoginInfo, @@ -52,6 +53,7 @@ import { ServiceProtocolService, UserPasswordSetResponse } from '@ucap-webmessenger/protocol-service'; +import { AuthenticationProtocolService } from '@ucap-webmessenger/protocol-authentication'; @Injectable() export class Effects { @@ -122,21 +124,33 @@ export class Effects { this.actions$.pipe( ofType(loginRedirect), tap(authed => { - this.router.navigate(['/account/login']); + this.ngZone.run(() => { + this.router.navigate(['/account/login']).then(() => { + this.store.dispatch(logoutInitialize()); + location.reload(); + }); + }); }) ), { dispatch: false } ); - logout$ = createEffect(() => - this.actions$.pipe( - ofType(logout), - map(action => action), - map(() => { - this.appAuthenticationService.logout(); - return loginRedirect(); - }) - ) + logout$ = createEffect( + () => { + return this.actions$.pipe( + ofType(logout), + switchMap(action => { + return this.authenticationProtocolService.logout({}).pipe( + map(res => { + this.appAuthenticationService.logout(); + this.store.dispatch(loginRedirect()); + }), + catchError(error => of(error)) + ); + }) + ); + }, + { dispatch: false } ); logoutConfirmation$ = createEffect(() => @@ -288,11 +302,13 @@ export class Effects { constructor( private actions$: Actions, + private ngZone: NgZone, private router: Router, private store: Store, private sessionStorageService: SessionStorageService, private piService: PiService, private appAuthenticationService: AppAuthenticationService, + private authenticationProtocolService: AuthenticationProtocolService, private serviceProtocolService: ServiceProtocolService, private dialogService: DialogService, @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, diff --git a/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts index 1f91456d..a00d9ba7 100644 --- a/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/account/authentication/reducers.ts @@ -3,7 +3,9 @@ import { State, initialState } from './state'; import { loginSuccess, increaseLoginFailCount, - initialLoginFailCount + initialLoginFailCount, + logout, + logoutInitialize } from './actions'; export const reducer = createReducer( @@ -21,10 +23,17 @@ export const reducer = createReducer( loginFailCount: state.loginFailCount + 1 }; }), + on(initialLoginFailCount, (state, action) => { return { ...state, loginFailCount: 0 }; + }), + + on(logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts index 7dbb464e..4e2d4aab 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/chat/reducers.ts @@ -11,6 +11,8 @@ import { clearRightDrawer } from './actions'; +import * as AuthenticationStore from '@app/store/account/authentication'; + export const reducer = createReducer( initialState, on(selectedRoom, (state, action) => { @@ -64,5 +66,11 @@ export const reducer = createReducer( ...state, selectedRightDrawer: null }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts index a6706e54..418faec2 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts @@ -128,12 +128,13 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(ChatStore.clearSelectedRoom, (state, action) => { return { ...initialState }; }), - on(ChatStore.clearSelectedRoom, (state, action) => { + + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts index df652195..148e07aa 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/option/reducers.ts @@ -17,7 +17,7 @@ export const reducer = createReducer( reg: action.res }; }), - on(AuthenticationStore.logout, (state, action) => { + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts index 4e26fb20..fecef243 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/query/reducers.ts @@ -49,7 +49,7 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts index e33bc262..aa09416f 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/room/reducers.ts @@ -64,12 +64,13 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(ChatStore.clearSelectedRoom, (state, action) => { return { ...initialState }; }), - on(ChatStore.clearSelectedRoom, (state, action) => { + + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts index 97e46b0f..c65060d2 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts @@ -42,7 +42,7 @@ export const reducer = createReducer( }; }), - on(AuthenticationStore.logout, (state, action) => { + on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts index 6e9ad92b..e253f0de 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts @@ -30,6 +30,8 @@ import * as RoomStore from '@app/store/messenger/room'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; import { StringUtil } from '@ucap-webmessenger/ui'; +import * as AuthenticationStore from '@app/store/account/authentication'; + export const reducer = createReducer( initialState, on(buddy2Success, (state, action) => { @@ -283,5 +285,11 @@ export const reducer = createReducer( ...state, buddy2: adapterBuddy2.upsertOne(userInfo, { ...state.buddy2 }) }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts index 53a9e594..18e6202e 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/company/reducers.ts @@ -1,4 +1,7 @@ import { createReducer, on } from '@ngrx/store'; + +import * as AuthenticationStore from '@app/store/account/authentication'; + import { initialState } from './state'; import { companyListSuccess } from './actions'; @@ -9,5 +12,11 @@ export const reducer = createReducer( ...state, companyList: action.companyList }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) ); diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts index b924cee4..dc00e708 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts @@ -2,6 +2,8 @@ import { createReducer, on } from '@ngrx/store'; import { initialState } from './state'; import { versionInfo2Success } from './actions'; +import * as AuthenticationStore from '@app/store/account/authentication'; + export const reducer = createReducer( initialState, on(versionInfo2Success, (state, action) => { @@ -19,5 +21,11 @@ export const reducer = createReducer( fileDownloadUrl: action.res.downloadUrl, serverIp: action.res.serverIp }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; }) );