2019-11-19 18:43:49 +09:00
|
|
|
import { Injectable, Inject, NgZone } from '@angular/core';
|
2019-09-18 15:02:21 +09:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
2019-11-13 15:28:33 +09:00
|
|
|
import { of, Observable } from 'rxjs';
|
2019-10-02 14:34:17 +09:00
|
|
|
import { catchError, exhaustMap, map, tap, switchMap } from 'rxjs/operators';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
2019-09-27 12:53:21 +09:00
|
|
|
import { Actions, ofType, createEffect } from '@ngrx/effects';
|
|
|
|
|
2019-10-04 10:19:55 +09:00
|
|
|
import {
|
|
|
|
PiService,
|
|
|
|
Login2Response,
|
2019-11-14 14:19:59 +09:00
|
|
|
UserTermsActionResponse
|
2019-10-04 10:19:55 +09:00
|
|
|
} from '@ucap-webmessenger/pi';
|
2019-09-19 17:03:39 +09:00
|
|
|
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
|
|
|
import {
|
|
|
|
DialogService,
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
2019-11-29 15:09:47 +09:00
|
|
|
ConfirmDialogResult,
|
2019-11-29 16:08:24 +09:00
|
|
|
SnackBarService,
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogData,
|
|
|
|
AlertDialogResult
|
2019-09-19 17:03:39 +09:00
|
|
|
} from '@ucap-webmessenger/ui';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
import {
|
|
|
|
loginRedirect,
|
2019-09-19 17:03:39 +09:00
|
|
|
logout,
|
|
|
|
logoutConfirmation,
|
2019-09-24 09:23:30 +09:00
|
|
|
logoutConfirmationDismiss,
|
|
|
|
webLogin,
|
|
|
|
webLoginSuccess,
|
2019-10-04 10:19:55 +09:00
|
|
|
webLoginFailure,
|
|
|
|
postLogin,
|
|
|
|
privacyAgree,
|
|
|
|
privacyDisagree,
|
|
|
|
privacyAgreeFailure,
|
|
|
|
privacyAgreeSuccess,
|
2019-11-14 14:19:59 +09:00
|
|
|
increaseLoginFailCount,
|
2019-11-19 18:43:49 +09:00
|
|
|
initialLoginFailCount,
|
2019-11-29 14:26:59 +09:00
|
|
|
logoutInitialize,
|
|
|
|
userPasswordSet,
|
|
|
|
userPasswordSetSuccess,
|
|
|
|
userPasswordSetFailure
|
2019-09-18 15:02:21 +09:00
|
|
|
} from './actions';
|
2019-10-04 10:19:55 +09:00
|
|
|
import {
|
|
|
|
LoginInfo,
|
|
|
|
KEY_LOGIN_INFO,
|
|
|
|
EnvironmentsInfo,
|
2019-11-14 14:19:59 +09:00
|
|
|
KEY_ENVIRONMENTS_INFO
|
2019-10-04 10:19:55 +09:00
|
|
|
} from '@app/types';
|
|
|
|
import { AppAuthenticationService } from '@app/services/authentication.service';
|
2019-09-27 12:53:21 +09:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-10-04 10:19:55 +09:00
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
2019-11-28 18:12:20 +09:00
|
|
|
|
2019-11-25 10:47:44 +09:00
|
|
|
import {
|
|
|
|
AuthenticationProtocolService,
|
|
|
|
LoginResponse
|
|
|
|
} from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type';
|
2019-11-28 13:19:19 +09:00
|
|
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
2019-11-28 14:02:07 +09:00
|
|
|
import { environment } from '../../../../environments/environment';
|
2019-11-28 15:48:36 +09:00
|
|
|
import {
|
|
|
|
ChangePasswordDialogComponent,
|
|
|
|
ChangePasswordDialogData,
|
|
|
|
ChangePasswordDialogResult
|
|
|
|
} from '@app/layouts/messenger/dialogs/account/change-password.dialog.component';
|
2019-11-29 14:26:59 +09:00
|
|
|
import {
|
|
|
|
ServiceProtocolService,
|
|
|
|
UserPasswordSetResponse
|
|
|
|
} from '@ucap-webmessenger/protocol-service';
|
2019-11-28 14:02:07 +09:00
|
|
|
|
2019-09-18 15:02:21 +09:00
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
2019-10-02 14:34:17 +09:00
|
|
|
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,
|
2019-11-14 14:19:59 +09:00
|
|
|
companyCode: params.loginInfo.companyCode
|
2019-10-02 14:34:17 +09:00
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
map((res: Login2Response) => {
|
|
|
|
if ('success' !== res.status.toLowerCase()) {
|
2019-11-14 14:19:59 +09:00
|
|
|
this.store.dispatch(increaseLoginFailCount({}));
|
2019-10-02 14:34:17 +09:00
|
|
|
return webLoginFailure({ error: 'Failed' });
|
|
|
|
} else {
|
2019-11-14 14:19:59 +09:00
|
|
|
this.store.dispatch(initialLoginFailCount({}));
|
2019-10-02 14:34:17 +09:00
|
|
|
return webLoginSuccess({
|
|
|
|
loginInfo: params.loginInfo,
|
|
|
|
rememberMe: params.rememberMe,
|
2019-11-14 14:19:59 +09:00
|
|
|
login2Response: res
|
2019-10-02 14:34:17 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(webLoginFailure({ error })))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2019-09-18 15:02:21 +09:00
|
|
|
);
|
|
|
|
|
2019-09-24 09:23:30 +09:00
|
|
|
webLoginSuccess$ = createEffect(
|
2019-09-19 14:15:43 +09:00
|
|
|
() =>
|
|
|
|
this.actions$.pipe(
|
2019-09-24 09:23:30 +09:00
|
|
|
ofType(webLoginSuccess),
|
2019-11-13 15:28:33 +09:00
|
|
|
switchMap(
|
|
|
|
params =>
|
|
|
|
new Observable<void>(subscriber => {
|
|
|
|
this.nativeService
|
|
|
|
.checkForUpdates()
|
|
|
|
.then((update: boolean) => {
|
|
|
|
if (!update) {
|
|
|
|
this.appAuthenticationService.login(
|
|
|
|
params.loginInfo,
|
|
|
|
params.rememberMe
|
|
|
|
);
|
|
|
|
this.router.navigate(['/messenger']);
|
|
|
|
}
|
|
|
|
subscriber.next();
|
|
|
|
})
|
|
|
|
.catch(reason => {
|
|
|
|
subscriber.error(reason);
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
subscriber.complete();
|
|
|
|
});
|
|
|
|
})
|
2019-09-24 18:42:53 +09:00
|
|
|
)
|
2019-09-19 14:15:43 +09:00
|
|
|
),
|
|
|
|
{ dispatch: false }
|
2019-09-18 15:02:21 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
loginRedirect$ = createEffect(
|
|
|
|
() =>
|
|
|
|
this.actions$.pipe(
|
2019-09-19 17:03:39 +09:00
|
|
|
ofType(loginRedirect),
|
2019-09-18 15:02:21 +09:00
|
|
|
tap(authed => {
|
2019-11-28 13:19:19 +09:00
|
|
|
// this.ngZone.run(() => {
|
|
|
|
// location.href = this.router.parseUrl('/account/login').toString();
|
2019-11-28 15:48:36 +09:00
|
|
|
this.router.navigate(['/account/login']);
|
2019-11-28 13:19:19 +09:00
|
|
|
this.appAuthenticationService.logout();
|
|
|
|
this.store.dispatch(logoutInitialize());
|
|
|
|
// });
|
2019-09-18 15:02:21 +09:00
|
|
|
})
|
|
|
|
),
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-11-19 18:43:49 +09:00
|
|
|
logout$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(logout),
|
|
|
|
switchMap(action => {
|
|
|
|
return this.authenticationProtocolService.logout({}).pipe(
|
|
|
|
map(res => {
|
2019-11-28 13:19:19 +09:00
|
|
|
this.protocolService.disconnect();
|
2019-11-19 18:43:49 +09:00
|
|
|
this.store.dispatch(loginRedirect());
|
|
|
|
}),
|
|
|
|
catchError(error => of(error))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
2019-09-19 17:03:39 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
logoutConfirmation$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(logoutConfirmation),
|
|
|
|
exhaustMap(async () => {
|
2019-11-25 10:47:44 +09:00
|
|
|
const loginRes = this.sessionStorageService.get<LoginResponse>(
|
|
|
|
KEY_LOGIN_RES_INFO
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!!loginRes && loginRes.userSeq) {
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
|
|
|
ConfirmDialogResult
|
|
|
|
>(ConfirmDialogComponent, {
|
|
|
|
data: {
|
|
|
|
title: 'Logout',
|
|
|
|
message: '로그아웃 하시겠습니까?'
|
|
|
|
}
|
|
|
|
});
|
2019-09-19 17:03:39 +09:00
|
|
|
|
2019-11-25 10:47:44 +09:00
|
|
|
return result.choice;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-19 17:03:39 +09:00
|
|
|
}),
|
|
|
|
map(result => (result ? logout() : logoutConfirmationDismiss()))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-10-04 10:19:55 +09:00
|
|
|
postLogin$ = createEffect(
|
|
|
|
() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(postLogin),
|
|
|
|
map(action => action.loginRes),
|
|
|
|
tap(async loginRes => {
|
|
|
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(
|
|
|
|
KEY_LOGIN_INFO
|
|
|
|
);
|
|
|
|
const environmentsInfo = this.sessionStorageService.get<
|
|
|
|
EnvironmentsInfo
|
|
|
|
>(KEY_ENVIRONMENTS_INFO);
|
|
|
|
|
2019-11-28 14:02:07 +09:00
|
|
|
if (
|
|
|
|
environment.productConfig.authentication
|
|
|
|
.usePrivateInformationAgree &&
|
|
|
|
!loginRes.privateInformationAgree
|
|
|
|
) {
|
2019-10-04 10:19:55 +09:00
|
|
|
const privacyTotalUrl = this.piService.privacyTotalUrl({
|
|
|
|
companyCode: loginInfo.companyCode,
|
|
|
|
userSeq: loginRes.userSeq,
|
|
|
|
token: loginRes.tokenString,
|
|
|
|
deviceType: environmentsInfo.deviceType,
|
|
|
|
localeCode: loginInfo.localeCode,
|
2019-11-14 14:19:59 +09:00
|
|
|
textOnly: 'true'
|
2019-10-04 10:19:55 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const result = await this.dialogService.open<
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
|
|
|
ConfirmDialogResult
|
|
|
|
>(ConfirmDialogComponent, {
|
|
|
|
width: '100%',
|
|
|
|
height: '500px',
|
|
|
|
disableClose: true,
|
|
|
|
data: {
|
2019-11-28 13:19:19 +09:00
|
|
|
title: '개인정보 동의',
|
|
|
|
html: `<iframe id="ifm_privacy" src="${privacyTotalUrl}" style="width: 100%;height: 300px;" />`
|
2019-11-14 14:19:59 +09:00
|
|
|
}
|
2019-10-04 10:19:55 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
if (result.choice) {
|
|
|
|
this.store.dispatch(privacyAgree({ loginRes }));
|
|
|
|
} else {
|
|
|
|
this.store.dispatch(privacyDisagree());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 15:48:36 +09:00
|
|
|
if (loginInfo.initPw) {
|
|
|
|
this.store.dispatch(logout());
|
|
|
|
|
|
|
|
const passwordInitStep1Url = this.piService.passwordInitStep1Url({
|
|
|
|
localeCode: loginInfo.localeCode
|
|
|
|
});
|
|
|
|
|
2019-10-04 10:19:55 +09:00
|
|
|
const result = await this.dialogService.open<
|
|
|
|
ConfirmDialogComponent,
|
|
|
|
ConfirmDialogData,
|
|
|
|
ConfirmDialogResult
|
|
|
|
>(ConfirmDialogComponent, {
|
|
|
|
width: '100%',
|
|
|
|
height: '500px',
|
|
|
|
disableClose: true,
|
|
|
|
data: {
|
2019-11-28 15:48:36 +09:00
|
|
|
title: '패스워드 초기화',
|
|
|
|
html: `<iframe id="ifm_privacy" src="${passwordInitStep1Url}" style="width: 100%;height: 300px;" />`
|
2019-11-14 14:19:59 +09:00
|
|
|
}
|
2019-10-04 10:19:55 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
if (result.choice) {
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-11-28 15:48:36 +09:00
|
|
|
|
2019-12-03 14:30:41 +09:00
|
|
|
if (!loginRes.passwordValid) {
|
2019-11-28 15:48:36 +09:00
|
|
|
const result = await this.dialogService.open<
|
|
|
|
ChangePasswordDialogComponent,
|
|
|
|
ChangePasswordDialogData,
|
|
|
|
ChangePasswordDialogResult
|
|
|
|
>(ChangePasswordDialogComponent, {
|
|
|
|
width: '500px',
|
|
|
|
height: '500px',
|
|
|
|
disableClose: false,
|
2019-11-29 14:26:59 +09:00
|
|
|
data: {
|
|
|
|
loginId: loginInfo.loginId,
|
|
|
|
encryptedLoginPw: loginInfo.loginPw,
|
|
|
|
phoneNumber: loginRes.userInfo.hpNumber
|
|
|
|
}
|
2019-11-28 15:48:36 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!!result && result.choice) {
|
2019-11-29 14:26:59 +09:00
|
|
|
this.store.dispatch(
|
|
|
|
userPasswordSet({
|
|
|
|
req: {
|
|
|
|
companyCode: loginInfo.companyCode,
|
|
|
|
loginId: loginInfo.loginId,
|
|
|
|
oldLoginPw: result.currentLoginPw,
|
|
|
|
newLoginPw: result.newLoginPw
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2019-11-28 15:48:36 +09:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-10-04 10:19:55 +09:00
|
|
|
})
|
|
|
|
),
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
|
|
|
privacyAgree$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(privacyAgree),
|
|
|
|
map(action => {
|
|
|
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(
|
|
|
|
KEY_LOGIN_INFO
|
|
|
|
);
|
|
|
|
const environmentsInfo = this.sessionStorageService.get<
|
|
|
|
EnvironmentsInfo
|
|
|
|
>(KEY_ENVIRONMENTS_INFO);
|
|
|
|
|
|
|
|
return {
|
|
|
|
loginInfo,
|
|
|
|
environmentsInfo,
|
2019-11-14 14:19:59 +09:00
|
|
|
loginResponse: action.loginRes
|
2019-10-04 10:19:55 +09:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
exhaustMap(params =>
|
|
|
|
this.piService
|
|
|
|
.userTermsAction({
|
|
|
|
userSeq: params.loginResponse.userSeq,
|
|
|
|
token: params.loginResponse.tokenString,
|
2019-11-14 14:19:59 +09:00
|
|
|
deviceType: params.environmentsInfo.deviceType
|
2019-10-04 10:19:55 +09:00
|
|
|
})
|
|
|
|
.pipe(
|
|
|
|
map((res: UserTermsActionResponse) => {
|
|
|
|
if ('00' !== res.responseCode) {
|
|
|
|
return privacyAgreeFailure({ error: 'Failed' });
|
|
|
|
} else {
|
|
|
|
return privacyAgreeSuccess();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(privacyAgreeFailure({ error })))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-11-29 14:26:59 +09:00
|
|
|
userPasswordSet$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(userPasswordSet),
|
|
|
|
map(action => action.req),
|
|
|
|
exhaustMap(req =>
|
|
|
|
this.serviceProtocolService.userPasswordSet(req).pipe(
|
|
|
|
map((res: UserPasswordSetResponse) => {
|
|
|
|
return userPasswordSetSuccess({
|
|
|
|
res
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
catchError(error => of(userPasswordSetFailure({ error })))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-11-29 15:09:47 +09:00
|
|
|
userPasswordSetSuccess$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(userPasswordSetSuccess),
|
2019-11-29 16:08:24 +09:00
|
|
|
tap(async action => {
|
|
|
|
await this.dialogService.open<
|
|
|
|
AlertDialogComponent,
|
|
|
|
AlertDialogData,
|
|
|
|
AlertDialogResult
|
|
|
|
>(AlertDialogComponent, {
|
|
|
|
width: '360px',
|
|
|
|
disableClose: true,
|
|
|
|
data: {
|
|
|
|
title: '비밀번호 변경',
|
|
|
|
message: '비밀번호가 변경되었습니다. 다시 로그인하여 주십시오'
|
|
|
|
}
|
2019-11-29 15:09:47 +09:00
|
|
|
});
|
2019-11-29 16:08:24 +09:00
|
|
|
|
|
|
|
this.store.dispatch(logout());
|
2019-11-29 15:09:47 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
|
|
|
userPasswordSetFailure$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(userPasswordSetFailure),
|
|
|
|
tap(action => {
|
|
|
|
this.snackBarService.open(
|
|
|
|
`비밀번호 변경 중에 문제가 발생하였습니다.`,
|
|
|
|
'',
|
|
|
|
{
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'bottom'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-09-18 15:02:21 +09:00
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
2019-11-19 18:43:49 +09:00
|
|
|
private ngZone: NgZone,
|
2019-09-19 17:03:39 +09:00
|
|
|
private router: Router,
|
2019-10-04 10:19:55 +09:00
|
|
|
private store: Store<any>,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-09-18 15:02:21 +09:00
|
|
|
private piService: PiService,
|
2019-09-19 18:22:13 +09:00
|
|
|
private appAuthenticationService: AppAuthenticationService,
|
2019-11-28 13:19:19 +09:00
|
|
|
private protocolService: ProtocolService,
|
2019-11-19 18:43:49 +09:00
|
|
|
private authenticationProtocolService: AuthenticationProtocolService,
|
2019-11-29 14:26:59 +09:00
|
|
|
private serviceProtocolService: ServiceProtocolService,
|
2019-09-19 17:03:39 +09:00
|
|
|
private dialogService: DialogService,
|
2019-11-29 15:09:47 +09:00
|
|
|
private snackBarService: SnackBarService,
|
2019-09-27 12:53:21 +09:00
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
|
|
|
|
private logger: NGXLogger
|
2019-09-18 15:02:21 +09:00
|
|
|
) {}
|
|
|
|
}
|