diff --git a/projects/ucap-webmessenger-app/src/app/app-routing.module.ts b/projects/ucap-webmessenger-app/src/app/app-routing.module.ts index 6444944a..2c415702 100644 --- a/projects/ucap-webmessenger-app/src/app/app-routing.module.ts +++ b/projects/ucap-webmessenger-app/src/app/app-routing.module.ts @@ -1,7 +1,6 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { AppAuthGuard } from './guards/auth.guard'; -import { AppMessengerResolver } from './resolvers/messenger.resolver'; const routes: Routes = [ { path: '', redirectTo: '/messenger', pathMatch: 'full' }, @@ -9,10 +8,7 @@ const routes: Routes = [ path: 'messenger', loadChildren: './pages/messenger/messenger.page.module#AppMessengerPageModule', - canActivate: [AppAuthGuard], - resolve: { - protocol: AppMessengerResolver - } + canActivate: [AppAuthGuard] }, { path: 'account', diff --git a/projects/ucap-webmessenger-app/src/app/pages/messenger/messenger-routing.page.module.ts b/projects/ucap-webmessenger-app/src/app/pages/messenger/messenger-routing.page.module.ts index 9c5d16ac..511bb95b 100644 --- a/projects/ucap-webmessenger-app/src/app/pages/messenger/messenger-routing.page.module.ts +++ b/projects/ucap-webmessenger-app/src/app/pages/messenger/messenger-routing.page.module.ts @@ -2,12 +2,16 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { MainPageComponent } from './components/main.page.component'; +import { AppMessengerResolver } from '@app/resolvers/messenger.resolver'; const routes: Routes = [ { path: '', redirectTo: 'main', pathMatch: 'full' }, { path: 'main', - component: MainPageComponent + component: MainPageComponent, + resolve: { + protocol: AppMessengerResolver + } } ]; diff --git a/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts b/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts index e7228cf4..7652158b 100644 --- a/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts +++ b/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts @@ -4,17 +4,28 @@ import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; -import { Observable, throwError } from 'rxjs'; -import { map, tap, mergeMap, catchError, take } from 'rxjs/operators'; +import { Observable, throwError, of, EMPTY, forkJoin } from 'rxjs'; +import { + map, + tap, + mergeMap, + catchError, + take, + exhaustMap, + concatMap, + switchMap, + withLatestFrom +} from 'rxjs/operators'; -import { Store } from '@ngrx/store'; +import { Store, select } from '@ngrx/store'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; -import { PublicApiService } from '@ucap-webmessenger/api-public'; +import { + PublicApiService, + VersionInfo2Response +} from '@ucap-webmessenger/api-public'; -import * as AppStore from '../store'; -import * as VersionInfoStore from '../store/setting/version-info'; import { LoginInfo, KEY_LOGIN_INFO, @@ -29,6 +40,17 @@ import { } from '@ucap-webmessenger/protocol-authentication'; import * as AuthenticationStore from '@app/store/account/authentication'; +import { ConnResponse } from 'projects/ucap-webmessenger-protocol-inner/src/lib/models/conn'; +import { PiService } from '@ucap-webmessenger/pi'; +import { NGXLogger } from 'ngx-logger'; +import { QueryProtocolService } from '@ucap-webmessenger/protocol-query'; +import { OptionProtocolService } from '@ucap-webmessenger/protocol-option'; + +import * as AppStore from '@app/store'; +import * as VersionInfoStore from '@app/store/setting/version-info'; +import * as OptionStore from '@app/store/setting/option'; +import * as QueryStore from '@app/store/setting/query'; +import * as SyncStore from '@app/store/messenger/sync'; @Injectable() export class AppMessengerResolver implements Resolve { @@ -36,78 +58,115 @@ export class AppMessengerResolver implements Resolve { private store: Store, private sessionStorageService: SessionStorageService, private publicApiService: PublicApiService, + private piService: PiService, private protocolService: ProtocolService, + private queryProtocolService: QueryProtocolService, + private optionProtocolService: OptionProtocolService, private authenticationProtocolService: AuthenticationProtocolService, - private innerProtocolService: InnerProtocolService + private innerProtocolService: InnerProtocolService, + private logger: NGXLogger ) {} resolve( - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot + activatedRouteSnapshot: ActivatedRouteSnapshot, + routerStateSnapshot: RouterStateSnapshot ): void | Observable | Promise { - const loginInfo = this.sessionStorageService.get(KEY_LOGIN_INFO); - const environmentsInfo = this.sessionStorageService.get( - KEY_ENVIRONMENTS_INFO - ); - return new Promise((resolve, reject) => { - resolve(); - // this.publicApiService - // .versionInfo2({ - // deviceType: environmentsInfo.deviceType, - // companyGroupType: loginInfo.companyGroupType, - // companyCode: loginInfo.companyCode, - // loginId: loginInfo.loginId - // }) - // .pipe( - // take(1), - // tap(versionInfo2Res => { - // this.store.dispatch(VersionInfoStore.fetchSuccess(versionInfo2Res)); - // }), - // mergeMap(versionInfo2Res => - // this.protocolService.connect(versionInfo2Res.serverIp) - // ), - // mergeMap(() => this.innerProtocolService.conn({})), - // mergeMap(connRres => - // this.authenticationProtocolService.login({ - // loginId: loginInfo.loginId, - // loginPw: loginInfo.loginPw, - // deviceType: environmentsInfo.deviceType, - // deviceId: ' ', - // token: '', - // localeCode: loginInfo.localeCode, - // pushId: ' ', - // companyCode: loginInfo.companyCode, - // passwordEncodingType: 1, - // clientVersion: '', - // reconnect: false, - // ip: 'localhost', - // hostName: '', - // ssoMode: SSOMode.AUTH, - // userSpecificInformation: 'PRO_000482', - // productId: 'PRO_000482', - // productName: 'EZMessenger' - // }) - // ), - // map(loginRes => { - // this.store.dispatch( - // AuthenticationStore.loginSuccess({ - // loginInfo: loginRes - // }) - // ); - // }), - // catchError(err => { - // return throwError(err); - // }) - // ) - // .subscribe( - // () => { - // resolve(); - // }, - // err => { - // reject(); - // } - // ); + let versionInfo2Res: VersionInfo2Response; + let connRres: ConnResponse; + let loginRes: LoginResponse; + + const loginInfo = this.sessionStorageService.get( + KEY_LOGIN_INFO + ); + const environmentsInfo = this.sessionStorageService.get( + KEY_ENVIRONMENTS_INFO + ); + + this.publicApiService + .versionInfo2({ + deviceType: environmentsInfo.deviceType, + companyGroupType: loginInfo.companyGroupType, + companyCode: loginInfo.companyCode, + loginId: loginInfo.loginId + }) + .pipe( + take(1), + switchMap(res => { + versionInfo2Res = res; + return this.protocolService.connect(versionInfo2Res.serverIp); + }), + switchMap(() => this.innerProtocolService.conn({})), + switchMap(res => { + connRres = res; + return this.authenticationProtocolService.login({ + loginId: loginInfo.loginId, + loginPw: loginInfo.loginPw, + deviceType: environmentsInfo.deviceType, + deviceId: ' ', + token: '', + localeCode: loginInfo.localeCode, + pushId: ' ', + companyCode: loginInfo.companyCode, + passwordEncodingType: 1, + clientVersion: '', + reconnect: false, + ip: 'localhost', + hostName: '', + ssoMode: SSOMode.AUTH, + userSpecificInformation: 'PRO_000482', + productId: 'PRO_000482', + productName: 'EZMessenger' + }); + }), + switchMap(res => + forkJoin([ + this.queryProtocolService.auth({ + deviceType: environmentsInfo.deviceType + }), + this.optionProtocolService.regView({}) + ]) + ), + tap(([authRes, regViewRes]) => { + this.store.dispatch( + OptionStore.regViewSuccess({ res: regViewRes }) + ); + this.store.dispatch(QueryStore.authSuccess({ res: authRes })); + }), + withLatestFrom( + this.store.pipe( + select(AppStore.MessengerSelector.SyncSelector.buddy2SyncDate) + ), + this.store.pipe( + select(AppStore.MessengerSelector.SyncSelector.group2SyncDate) + ) + ), + map(([[], buddy2SyncDate, group2SyncDate]) => { + this.store.dispatch(SyncStore.buddy2({ syncDate: buddy2SyncDate })); + this.store.dispatch(SyncStore.group2({ syncDate: group2SyncDate })); + }), + catchError(err => { + return throwError(err); + }) + ) + .subscribe( + () => { + this.store.dispatch( + AuthenticationStore.loginSuccess({ + loginInfo: loginRes + }) + ); + console.log('next'); + resolve(); + }, + err => { + console.log('err', err); + reject(err); + }, + () => { + console.log('complete'); + } + ); }); } } 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 8ab465d2..a6095306 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,27 +1,12 @@ import { Injectable, Inject } from '@angular/core'; import { Router } from '@angular/router'; -import { of, throwError, EMPTY as empty } from 'rxjs'; -import { - catchError, - exhaustMap, - map, - tap, - take, - switchMap, - mergeMap, - skip, - concatMap -} from 'rxjs/operators'; +import { of } from 'rxjs'; +import { catchError, exhaustMap, map, tap, switchMap } from 'rxjs/operators'; -import { Store } from '@ngrx/store'; import { Actions, ofType, createEffect } from '@ngrx/effects'; -import { - PiService, - Login2Response, - ResponseStatus -} from '@ucap-webmessenger/pi'; +import { PiService, Login2Response } from '@ucap-webmessenger/pi'; import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native'; import { DialogService, @@ -31,8 +16,6 @@ import { } from '@ucap-webmessenger/ui'; import { - loginSuccess, - loginFailure, loginRedirect, logout, logoutConfirmation, @@ -41,265 +24,39 @@ import { webLoginSuccess, webLoginFailure } from './actions'; -import { - LoginInfo, - EnvironmentsInfo, - KEY_ENVIRONMENTS_INFO -} from '../../../types'; +import { LoginInfo } from '../../../types'; import { AppAuthenticationService } from '../../../services/authentication.service'; import { NGXLogger } from 'ngx-logger'; -import { - PublicApiService, - VersionInfo2Response -} from '@ucap-webmessenger/api-public'; -import { SessionStorageService } from '@ucap-webmessenger/web-storage'; - -import * as VersionInfoStore from '@app/store/setting/version-info'; -import { ProtocolService } from '@ucap-webmessenger/protocol'; -import { InnerProtocolService } from '@ucap-webmessenger/protocol-inner'; -import { - AuthenticationProtocolService, - SSOMode, - LoginResponse -} from '@ucap-webmessenger/protocol-authentication'; - -import CryptoJS from 'crypto-js'; @Injectable() export class Effects { - // webLogin$ = createEffect(() => - // this.actions$.pipe( - // ofType(webLogin), - // map(action => action), - // exhaustMap((params: { loginInfo: LoginInfo; rememberMe: boolean }) => - // this.piService - // .login2({ - // loginId: params.loginInfo.loginId, - // loginPw: params.loginInfo.loginPw, - // companyCode: params.loginInfo.companyCode - // }) - // .pipe( - // map((res: Login2Response) => { - // if ('success' !== res.status.toLowerCase()) { - // return webLoginFailure({ error: 'Failed' }); - // } else { - // return webLoginSuccess({ - // loginInfo: params.loginInfo, - // rememberMe: params.rememberMe, - // login2Response: res - // }); - // } - // }), - // catchError(error => of(webLoginFailure({ error }))) - // ) - // ) - // ) - // ); - webLogin$ = createEffect( - () => - this.actions$.pipe( - ofType(webLogin), - map(action => action), - switchMap( - (loginParams: { loginInfo: LoginInfo; rememberMe: boolean }) => { - const environmentsInfo = this.sessionStorageService.get< - EnvironmentsInfo - >(KEY_ENVIRONMENTS_INFO); - - let login2Res: Login2Response; - let loginRes: LoginResponse; - let versionInfo2Res: VersionInfo2Response; - let encLoginPw: string; - - return this.piService - .login2({ - loginId: loginParams.loginInfo.loginId, - loginPw: loginParams.loginInfo.loginPw, - companyCode: loginParams.loginInfo.companyCode - }) - .pipe( - concatMap(res => { - console.log('tap'); - if ('success' !== res.status.toLowerCase()) { - return throwError('login2 failed'); - } - login2Res = res; - return of(true); - }), - mergeMap(dd => { - console.log('checkForUpdates'); - return this.nativeService.checkForUpdates(); - }), - concatMap(update => { - if (update) { - return throwError('update process'); - } - encLoginPw = CryptoJS.enc.Hex.stringify( - CryptoJS.SHA256(loginParams.loginInfo.loginPw) - ); - return of(true); - }), - mergeMap(() => - this.publicApiService.versionInfo2({ - deviceType: environmentsInfo.deviceType, - companyGroupType: loginParams.loginInfo.companyGroupType, - companyCode: loginParams.loginInfo.companyCode, - loginId: loginParams.loginInfo.loginId - }) - ), - map(res => { - this.store.dispatch(VersionInfoStore.fetchSuccess(res)); - versionInfo2Res = res; - return of(true); - }), - mergeMap(() => - this.protocolService.connect(versionInfo2Res.serverIp) - ), - mergeMap(() => this.innerProtocolService.conn({})), - mergeMap(() => - this.authenticationProtocolService.login({ - loginId: loginParams.loginInfo.loginId, - loginPw: encLoginPw, - deviceType: environmentsInfo.deviceType, - deviceId: ' ', - token: '', - localeCode: loginParams.loginInfo.localeCode, - pushId: ' ', - companyCode: loginParams.loginInfo.companyCode, - passwordEncodingType: 1, - clientVersion: '', - reconnect: false, - ip: 'localhost', - hostName: '', - ssoMode: SSOMode.AUTH, - userSpecificInformation: 'PRO_000482', - productId: 'PRO_000482', - productName: 'EZMessenger' - }) - ), - exhaustMap(async res => { - if (res.privateInformationAgree) { - return of(null); - } - - loginRes = res; - - const privacyTotalUrl = this.piService.privacyTotalUrl({ - companyCode: res.companyCode, - userSeq: res.userSeq, - token: res.tokenString, - deviceType: environmentsInfo.deviceType, - localeCode: loginParams.loginInfo.localeCode, - textOnly: 'true' - }); - - const result = await this.dialogService.open< - ConfirmDialogComponent, - ConfirmDialogData, - ConfirmDialogResult - >(ConfirmDialogComponent, { - width: '100%', - height: '500px', - disableClose: true, - data: { - title: '개인정보 동의', - html: `