자동 로그인 && 네트워크 절체시 로직 변경.

1. retry 시간 10분 > 1분. (3초간격)
2. 최종 실패시 앱종료 > 로그인페이지로.
This commit is contained in:
leejinho 2020-03-25 11:40:37 +09:00
parent 6d5073566b
commit 9a98298aa1
5 changed files with 123 additions and 27 deletions

View File

@ -60,8 +60,9 @@
[loginBtnText]="loginBtnText" [loginBtnText]="loginBtnText"
[companyCode]="appUserInfo?.companyCode" [companyCode]="appUserInfo?.companyCode"
[loginId]="appUserInfo?.loginId" [loginId]="appUserInfo?.loginId"
[loginPw]="loginPw"
[rememberMe]="appUserInfo?.rememberMe" [rememberMe]="appUserInfo?.rememberMe"
[autoLogin]="appUserInfo?.settings?.general?.autoLogin" [autoLogin]="autologin"
[useRememberMe]="useRememberMe" [useRememberMe]="useRememberMe"
[useAutoLogin]="useAutoLogin" [useAutoLogin]="useAutoLogin"
(login)="onLogin($event)" (login)="onLogin($event)"

View File

@ -63,6 +63,8 @@ export class LoginPageComponent implements OnInit, OnDestroy {
waitingTime: number; waitingTime: number;
appUserInfo: AppUserInfo; appUserInfo: AppUserInfo;
loginPw: string;
autologin: boolean;
useRememberMe: boolean; useRememberMe: boolean;
useAutoLogin: boolean; useAutoLogin: boolean;
@ -103,6 +105,9 @@ export class LoginPageComponent implements OnInit, OnDestroy {
KEY_APP_USER_INFO, KEY_APP_USER_INFO,
environment.customConfig.appKey environment.customConfig.appKey
); );
if (!!this.appUserInfo) {
this.autologin = this.appUserInfo.settings.general.autoLogin || false;
}
this.rotateInfomationIndex = this.rotateInfomationIndex =
new Date().getTime() % this.rotateInfomation.length; new Date().getTime() % this.rotateInfomation.length;
@ -218,6 +223,56 @@ export class LoginPageComponent implements OnInit, OnDestroy {
this.nativeService.idleStateStop(); this.nativeService.idleStateStop();
} }
/** CASE :: 자동로그인 실패 (비밀번호 변경에 따른 실패, 네트워크 절체) */
if (!!personLogout && !!personLogout.autoLogin) {
switch (personLogout.autoLogin.state) {
case 'IDPW_FAIL':
{
this.ngZone.run(() => {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
title: '',
html: this.translateService.instant(
'accounts.errors.loginFailedIdPw'
)
}
});
});
}
break;
case 'NETWORK_FAIL':
{
this.loginPw = this.appUserInfo.loginPw;
this.autologin = true;
this.ngZone.run(() => {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
title: this.translateService.instant(
'accounts.errors.loginFailed'
),
html: this.translateService.instant(
'accounts.errors.networkFailedAndRetry'
)
}
});
});
}
break;
}
}
/** CASE :: 중복 로그인, Remote 로그아웃 */
if (!!personLogout && !!personLogout.reasonCode) { if (!!personLogout && !!personLogout.reasonCode) {
let msg = this.translateService.instant('accounts.results.doLogout'); let msg = this.translateService.instant('accounts.results.doLogout');
switch (personLogout.reasonCode) { switch (personLogout.reasonCode) {
@ -300,6 +355,8 @@ export class LoginPageComponent implements OnInit, OnDestroy {
autoLogin: boolean; autoLogin: boolean;
notValid: () => void; notValid: () => void;
}) { }) {
this.sessionStorageService.remove(KEY_LOGOUT_INFO);
this.loginBtnEnable = false; this.loginBtnEnable = false;
setTimeout(() => { setTimeout(() => {
this.loginBtnEnable = true; this.loginBtnEnable = true;

View File

@ -94,7 +94,7 @@ import { StatusCode } from '@ucap-webmessenger/api';
export class Effects { export class Effects {
retryCount = 0; retryCount = 0;
retryInterval = 3000; // ms retryInterval = 3000; // ms
maxRetryCount = (10 * 60 * 1000) / this.retryInterval; // 200 count due to 10 min. maxRetryCount = (1 * 60 * 1000) / this.retryInterval; // 20 count due to 1 min.
webLogin$ = createEffect( webLogin$ = createEffect(
() => () =>
this.actions$.pipe( this.actions$.pipe(
@ -119,8 +119,29 @@ export class Effects {
if ('success' !== res.status.toLowerCase()) { if ('success' !== res.status.toLowerCase()) {
if (!!params.autoLogin) { if (!!params.autoLogin) {
// auto login Failure. // auto login Failure.
this.store.dispatch(increaseLoginFailCount({})); // clear setting for autologin.
this.localStorageService.remove(KEY_APP_USER_INFO); // this.localStorageService.remove(KEY_APP_USER_INFO);
const appUserInfo = this.localStorageService.encGet<
AppUserInfo
>(KEY_APP_USER_INFO, environment.customConfig.appKey);
appUserInfo.settings.general.autoLogin = false;
this.localStorageService.encSet<AppUserInfo>(
KEY_APP_USER_INFO,
appUserInfo,
environment.customConfig.appKey
);
// Logout reason setting.
this.sessionStorageService.set<LogoutInfo>(
KEY_LOGOUT_INFO,
{
personLogout: true,
autoLogin: {
state: 'IDPW_FAIL'
}
} as LogoutInfo
);
this.router.navigateByUrl('/account/login'); this.router.navigateByUrl('/account/login');
} else { } else {
this.store.dispatch(increaseLoginFailCount({})); this.store.dispatch(increaseLoginFailCount({}));
@ -156,29 +177,32 @@ export class Effects {
this.retryCount, this.retryCount,
this.maxRetryCount this.maxRetryCount
); );
}
}
this.ngZone.run(async () => {
const result = await this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
title: this.translateService.instant(
'accounts.errors.loginFailed'
),
html: this.translateService.instant(
'accounts.errors.networkFailedAndExit'
)
}
});
if (!!result) { // clear setting for autologin.
this.nativeService.appExit(); const appUserInfo = this.localStorageService.encGet<
AppUserInfo
>(KEY_APP_USER_INFO, environment.customConfig.appKey);
appUserInfo.settings.general.autoLogin = false;
this.localStorageService.encSet<AppUserInfo>(
KEY_APP_USER_INFO,
appUserInfo,
environment.customConfig.appKey
);
// Logout reason setting.
this.sessionStorageService.set<LogoutInfo>(
KEY_LOGOUT_INFO,
{
personLogout: true,
autoLogin: {
state: 'NETWORK_FAIL'
} }
}); } as LogoutInfo
);
}
}
this.router.navigateByUrl('/account/login');
console.log('not retry'); console.log('not retry');
return of(webLoginFailure({ error })); return of(webLoginFailure({ error }));

View File

@ -2,8 +2,17 @@ export const KEY_LOGOUT_INFO = 'ucap::LOGOUT_INFO';
export interface LogoutInfo { export interface LogoutInfo {
personLogout: boolean; personLogout: boolean;
/** 중복로그인, Remote 로그아웃 시에 사용. */
reasonCode?: number; reasonCode?: number;
ip?: string; ip?: string; // 중복로그인시 사용.
mac?: string; mac?: string; // 중복로그인시 사용.
forceType?: string; forceType?: string; // remote 로그아웃 시 사용.
/** 자동로그인 실패시. */
autoLogin?: {
state: string;
id?: string;
pw?: string;
};
} }

View File

@ -39,6 +39,8 @@ export class LoginComponent implements OnInit {
@Input() @Input()
loginId: string; loginId: string;
@Input() @Input()
loginPw?: string;
@Input()
rememberMe: boolean; rememberMe: boolean;
@Input() @Input()
autoLogin: boolean; autoLogin: boolean;
@ -85,6 +87,9 @@ export class LoginComponent implements OnInit {
} }
const loginPwValidators: ValidatorFn[] = [Validators.required]; const loginPwValidators: ValidatorFn[] = [Validators.required];
this.loginPwFormControl.setValidators(loginPwValidators); this.loginPwFormControl.setValidators(loginPwValidators);
if (!!this.loginPw) {
this.loginPwFormControl.setValue(this.loginPw);
}
this.loginForm = this.formBuilder.group({ this.loginForm = this.formBuilder.group({
companyCodeFormControl: this.companyCodeFormControl, companyCodeFormControl: this.companyCodeFormControl,