diff --git a/projects/ucap-webmessenger-app/src/app/guards/auto-login.guard.ts b/projects/ucap-webmessenger-app/src/app/guards/auto-login.guard.ts new file mode 100644 index 00000000..6f91e389 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/guards/auto-login.guard.ts @@ -0,0 +1,60 @@ +import { Injectable } from '@angular/core'; +import { + CanActivate, + ActivatedRouteSnapshot, + RouterStateSnapshot, + UrlTree, + Router +} from '@angular/router'; +import { Store } from '@ngrx/store'; +import { Observable } from 'rxjs'; + +import { LocalStorageService } from '@ucap-webmessenger/web-storage'; +import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type'; +import { environment } from '../../environments/environment'; +import * as AuthenticationStore from '@app/store/account/authentication'; + +@Injectable({ + providedIn: 'root' +}) +export class AppAutoLoginGuard implements CanActivate { + constructor( + private router: Router, + private store: Store, + private localStorageService: LocalStorageService + ) {} + + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot + ): + | boolean + | UrlTree + | Observable + | Promise { + return new Promise((resolve, reject) => { + const appUserInfo = this.localStorageService.encGet( + KEY_APP_USER_INFO, + environment.customConfig.appKey + ); + + if (!!appUserInfo && appUserInfo.autoLogin) { + this.store.dispatch( + AuthenticationStore.webLogin({ + loginInfo: { + companyCode: appUserInfo.companyCode, + companyGroupType: appUserInfo.companyGroupType, + loginId: appUserInfo.loginId, + loginPw: appUserInfo.loginPw + }, + rememberMe: appUserInfo.rememberMe, + autoLogin: appUserInfo.autoLogin + }) + ); + resolve(false); + } else { + resolve(true); + } + }); + } +} diff --git a/projects/ucap-webmessenger-app/src/app/pages/account/account-routing.page.module.ts b/projects/ucap-webmessenger-app/src/app/pages/account/account-routing.page.module.ts index e1d9ad79..5dfd652d 100644 --- a/projects/ucap-webmessenger-app/src/app/pages/account/account-routing.page.module.ts +++ b/projects/ucap-webmessenger-app/src/app/pages/account/account-routing.page.module.ts @@ -2,12 +2,14 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { LoginPageComponent } from './components/login.page.component'; +import { AppAutoLoginGuard } from '@app/guards/auto-login.guard'; const routes: Routes = [ { path: '', redirectTo: '/account/login', pathMatch: 'full' }, { path: 'login', - component: LoginPageComponent + component: LoginPageComponent, + canActivate: [AppAutoLoginGuard] } ]; diff --git a/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.html b/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.html index 235afb3e..326a4876 100644 --- a/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.html +++ b/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.html @@ -6,6 +6,12 @@ [notiText]="fixedNotiBtnText" [loginBtnEnable]="loginBtnEnable" [loginBtnText]="loginBtnText" + [companyCode]="appUserInfo?.companyCode" + [loginId]="appUserInfo?.loginId" + [rememberMe]="appUserInfo?.rememberMe" + [autoLogin]="appUserInfo?.autoLogin" + [useRememberMe]="useRememberMe" + [useAutoLogin]="useAutoLogin" (login)="onLogin($event)" (notiClick)="onClickNoti($event)" > diff --git a/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.ts b/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.ts index 3fd94218..86e616e4 100644 --- a/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.ts +++ b/projects/ucap-webmessenger-app/src/app/pages/account/components/login.page.component.ts @@ -23,6 +23,10 @@ import { NoticeDialogData } from '@app/layouts/messenger/dialogs/account/notice.dialog.component'; +import { environment } from '../../../../environments/environment'; +import { LocalStorageService } from '@ucap-webmessenger/web-storage'; +import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type'; + @Component({ selector: 'app-page-account-login', templateUrl: './login.page.component.html', @@ -44,11 +48,25 @@ export class LoginPageComponent implements OnInit, OnDestroy { defatulWaitingTime: number; waitingTime: number; + appUserInfo: AppUserInfo; + useRememberMe: boolean; + useAutoLogin: boolean; + constructor( private store: Store, private router: Router, - private dialogService: DialogService - ) {} + private dialogService: DialogService, + private localStorageService: LocalStorageService + ) { + this.useRememberMe = + environment.productConfig.authentication.rememberMe.use; + this.useAutoLogin = environment.productConfig.authentication.autoLogin.use; + + this.appUserInfo = this.localStorageService.encGet( + KEY_APP_USER_INFO, + environment.customConfig.appKey + ); + } ngOnInit(): void { this.defatulLoginBtnText = 'LOGIN'; @@ -152,6 +170,7 @@ export class LoginPageComponent implements OnInit, OnDestroy { loginId: string; loginPw: string; rememberMe: boolean; + autoLogin: boolean; notValid: () => void; }) { this.store.dispatch( @@ -162,7 +181,8 @@ export class LoginPageComponent implements OnInit, OnDestroy { loginId: value.loginId, loginPw: value.loginPw }, - rememberMe: value.rememberMe + rememberMe: value.rememberMe, + autoLogin: value.autoLogin }) ); } diff --git a/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts b/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts index b050fded..0d37ac5e 100644 --- a/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts @@ -14,6 +14,9 @@ import { import { PasswordUtil } from '@ucap-webmessenger/pi'; import { DaesangCipherService } from '@ucap-webmessenger/daesang'; +import { environment } from '../../environments/environment'; +import { AppUserInfo, KEY_APP_USER_INFO } from '@app/types/app-user-info.type'; + @Injectable({ providedIn: 'root' }) @@ -31,25 +34,33 @@ export class AppAuthenticationService { return null !== loginInfo && !!loginInfo.loginId; } - login(loginInfo: LoginInfo, rememberMe: boolean) { + login(loginInfo: LoginInfo, rememberMe: boolean, autoLogin: boolean) { loginInfo = { ...loginInfo, localeCode: LocaleCode.Korean }; + const encLoginPw = this.daesangCipherService.encrypt( + environment.customConfig.pw.userKey, + loginInfo.loginPw, + environment.customConfig.pw.isBase64 + ); + // PasswordUtil.encrypt(loginInfo.loginPw) + this.sessionStorageService.set(KEY_LOGIN_INFO, { ...loginInfo, initPw: loginInfo.loginId === loginInfo.loginPw, - // loginPw: PasswordUtil.encrypt(loginInfo.loginPw) - loginPw: this.daesangCipherService.encrypt( - 'DaesangSSOProject', - loginInfo.loginPw, - 'N' - ) + loginPw: encLoginPw }); - if (rememberMe) { - this.localStorageService.set(KEY_LOGIN_INFO, { - ...loginInfo, - loginPw: undefined - }); + if (rememberMe || autoLogin) { + this.localStorageService.encSet( + KEY_APP_USER_INFO, + { + ...loginInfo, + loginPw: autoLogin ? loginInfo.loginPw : undefined, + rememberMe, + autoLogin + }, + environment.customConfig.appKey + ); } else { this.localStorageService.remove(KEY_LOGIN_INFO); } 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 b2ddbf81..c0e6456c 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 @@ -14,6 +14,7 @@ export const webLogin = createAction( props<{ loginInfo: LoginInfo; rememberMe: boolean; + autoLogin: boolean; }>() ); @@ -22,6 +23,7 @@ export const webLoginSuccess = createAction( props<{ loginInfo: LoginInfo; rememberMe: boolean; + autoLogin: boolean; login2Response: Login2Response; }>() ); 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 a59fdb02..69109fae 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 @@ -78,29 +78,35 @@ export class Effects { 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()) { - this.store.dispatch(increaseLoginFailCount({})); - return webLoginFailure({ error: 'Failed' }); - } else { - this.store.dispatch(initialLoginFailCount({})); - return webLoginSuccess({ - loginInfo: params.loginInfo, - rememberMe: params.rememberMe, - login2Response: res - }); - } - }), - catchError(error => of(webLoginFailure({ error }))) - ) + exhaustMap( + (params: { + loginInfo: LoginInfo; + rememberMe: boolean; + autoLogin: 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()) { + this.store.dispatch(increaseLoginFailCount({})); + return webLoginFailure({ error: 'Failed' }); + } else { + this.store.dispatch(initialLoginFailCount({})); + return webLoginSuccess({ + loginInfo: params.loginInfo, + rememberMe: params.rememberMe, + autoLogin: params.autoLogin, + login2Response: res + }); + } + }), + catchError(error => of(webLoginFailure({ error }))) + ) ) ) ); @@ -118,7 +124,8 @@ export class Effects { if (!update) { this.appAuthenticationService.login( params.loginInfo, - params.rememberMe + params.rememberMe, + params.autoLogin ); this.router.navigate(['/messenger']); } diff --git a/projects/ucap-webmessenger-app/src/app/types/app-user-info.type.ts b/projects/ucap-webmessenger-app/src/app/types/app-user-info.type.ts new file mode 100644 index 00000000..852fe399 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/types/app-user-info.type.ts @@ -0,0 +1,13 @@ +import { LocaleCode } from '@ucap-webmessenger/core'; + +export const KEY_APP_USER_INFO = 'ucap::APP_USER_INFO'; + +export interface AppUserInfo { + loginId?: string; + loginPw?: string; + rememberMe?: boolean; + autoLogin?: boolean; + companyCode?: string; + companyGroupType?: string; + localeCode?: LocaleCode; +} diff --git a/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts b/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts index d7cb303f..97fb1ba0 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.daesang.dev.ts @@ -22,7 +22,13 @@ export const environment: Environment = { productId: 'PRO_000482', productName: 'EZMessenger', authentication: { - usePrivateInformationAgree: false + usePrivateInformationAgree: false, + rememberMe: { + use: false + }, + autoLogin: { + use: true + } }, updateCheckConfig: { deviceType: DeviceType.Renderer, @@ -30,6 +36,14 @@ export const environment: Environment = { } }, + customConfig: { + pw: { + userKey: 'DaesangSSOProject', + isBase64: 'N' + }, + appKey: '!@#$DAESANG%^&*' + }, + commonApiModuleConfig: { hostConfig: { protocol: 'http', diff --git a/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts b/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts index be59dd85..7a54779c 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.daesang.prod.ts @@ -22,7 +22,13 @@ export const environment: Environment = { productId: 'PRO_000482', productName: 'EZMessenger', authentication: { - usePrivateInformationAgree: false + usePrivateInformationAgree: false, + rememberMe: { + use: false + }, + autoLogin: { + use: true + } }, updateCheckConfig: { deviceType: DeviceType.Renderer, @@ -30,6 +36,14 @@ export const environment: Environment = { } }, + customConfig: { + pw: { + userKey: 'DaesangSSOProject', + isBase64: 'N' + }, + appKey: '!@#$DAESANG%^&*' + }, + commonApiModuleConfig: { hostConfig: { protocol: 'http', diff --git a/projects/ucap-webmessenger-app/src/environments/environment.dev.ts b/projects/ucap-webmessenger-app/src/environments/environment.dev.ts index 1e75b076..584c843a 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.dev.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.dev.ts @@ -22,7 +22,13 @@ export const environment: Environment = { productId: 'PRO_000482', productName: 'EZMessenger', authentication: { - usePrivateInformationAgree: false + usePrivateInformationAgree: false, + rememberMe: { + use: false + }, + autoLogin: { + use: true + } }, updateCheckConfig: { deviceType: DeviceType.Renderer, diff --git a/projects/ucap-webmessenger-app/src/environments/environment.prod.ts b/projects/ucap-webmessenger-app/src/environments/environment.prod.ts index f411932b..51cf579c 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.prod.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.prod.ts @@ -22,7 +22,13 @@ export const environment: Environment = { productId: 'PRO_000482', productName: 'EZMessenger', authentication: { - usePrivateInformationAgree: false + usePrivateInformationAgree: false, + rememberMe: { + use: false + }, + autoLogin: { + use: true + } }, updateCheckConfig: { deviceType: DeviceType.Renderer, diff --git a/projects/ucap-webmessenger-app/src/environments/environment.type.ts b/projects/ucap-webmessenger-app/src/environments/environment.type.ts index 53c99610..2d5dfe41 100644 --- a/projects/ucap-webmessenger-app/src/environments/environment.type.ts +++ b/projects/ucap-webmessenger-app/src/environments/environment.type.ts @@ -44,6 +44,12 @@ export interface Environment { productName: string; authentication: { usePrivateInformationAgree: boolean; + rememberMe: { + use: boolean; + }; + autoLogin: { + use: boolean; + }; }; updateCheckConfig: { deviceType: DeviceType; @@ -51,6 +57,8 @@ export interface Environment { }; }; + customConfig?: any; + commonApiModuleConfig: CommonApiModuleConfig; publicApiModuleConfig: PublicApiModuleConfig; externalApiModuleConfig: ExternalApiModuleConfig; diff --git a/projects/ucap-webmessenger-ui-account/src/lib/components/login.component.html b/projects/ucap-webmessenger-ui-account/src/lib/components/login.component.html index 9a16cba9..6a658bf6 100644 --- a/projects/ucap-webmessenger-ui-account/src/lib/components/login.component.html +++ b/projects/ucap-webmessenger-ui-account/src/lib/components/login.component.html @@ -42,16 +42,22 @@ fxLayoutAlign="space-between center" > - Remember Me + 아이디 저장 - - Forgot Password? - +