261 lines
9.0 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, OnDestroy } from '@angular/core';
2019-09-18 15:02:21 +09:00
2019-09-26 14:38:21 +09:00
import { Store, select } from '@ngrx/store';
2019-09-18 15:02:21 +09:00
2019-09-26 14:38:21 +09:00
import { Company } from '@ucap-webmessenger/api-external';
2019-09-18 15:02:21 +09:00
2019-09-26 14:38:21 +09:00
import * as AppStore from '@app/store';
import * as AuthenticationStore from '@app/store/account/authentication';
import * as CompanyStore from '@app/store/setting/company';
import { Observable, Subscription } from 'rxjs';
2019-10-02 17:12:51 +09:00
import { Router } from '@angular/router';
import { tap, map } from 'rxjs/operators';
import {
DialogService,
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
} from '@ucap-webmessenger/ui';
import { StringUtil } from '@ucap-webmessenger/core';
import {
NoticeDialogComponent,
NoticeDialogResult,
NoticeDialogData
} from '@app/layouts/messenger/dialogs/account/notice.dialog.component';
2019-09-18 15:02:21 +09:00
2019-12-15 22:49:35 +09:00
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';
2019-09-18 15:02:21 +09:00
@Component({
selector: 'app-page-account-login',
templateUrl: './login.page.component.html',
styleUrls: ['./login.page.component.scss']
})
export class LoginPageComponent implements OnInit, OnDestroy {
fixedCompany: string;
fixedNotiBtnText: string;
2019-09-26 14:38:21 +09:00
companyList$: Observable<Company[]>;
2019-09-18 15:02:21 +09:00
loginFailureCount: Subscription;
defatulLoginBtnText: string;
loginBtnText: string;
loginBtnEnable: boolean;
timeChecker: any;
defatulWaitingTime: number;
waitingTime: number;
2019-12-15 22:49:35 +09:00
appUserInfo: AppUserInfo;
useRememberMe: boolean;
useAutoLogin: boolean;
rotateInfomationIntervalObject: any;
rotateInfomationIndex = 0;
rotateInfomation = [
{
index: 0,
content: `“ 고객의식탁에 건강한 먹거리와 행복한 미래를 제공합니다.”`,
info: `늘 가족의 곁에서 가족의 건강만을 생각하는 마음으로 진한 사랑과 정성을 담으려 합니다. 전통적인 맛에 현대적인 감각과 전문성을 더해, 건강한 식생활 문화를 다양한 곳으로 전달합니다.`
},
{
index: 1,
content: `“ 세계시장에 깊고 온화한 한국의 맛을 전파합니다! ”`,
info: `대상은 산업근대화 시기인 지난 70년대 초반, 국내 최초의 플랜트 수출 성공사례로 평가 받고 있는 인도네시아 진출을 계기로 해외시장 개척의 새로운 장을 열었습니다.
.`
},
{
index: 2,
content: `“ 나눌수록 맛있는 행복을 전합니다 ”`,
info: `다 함께 행복할 수 있는 세상을 만들기 위해 대상은 사회적 책임을 다합니다.
, .
, , `
}
];
constructor(
private store: Store<any>,
private router: Router,
2019-12-15 22:49:35 +09:00
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<AppUserInfo>(
KEY_APP_USER_INFO,
environment.customConfig.appKey
);
this.rotateInfomationIndex =
new Date().getTime() % this.rotateInfomation.length;
2019-12-15 22:49:35 +09:00
}
2019-09-18 15:02:21 +09:00
ngOnInit(): void {
this.rotateInfomationIntervalObject = setInterval(() => {
this.rotateInfomationIndex =
(this.rotateInfomationIndex + 1) % this.rotateInfomation.length;
}, 8000);
this.defatulLoginBtnText = 'LOGIN';
this.defatulWaitingTime = 5 * 60; // sec
2019-09-26 14:38:21 +09:00
this.store.dispatch(
CompanyStore.companyList({
companyGroupCode: environment.companyConfig.companyGroupCode
2019-09-26 14:38:21 +09:00
})
);
this.companyList$ = this.store.pipe(
select(AppStore.SettingSelector.CompanySelector.companyList)
);
this.loginFailureCount = this.store
.pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginFailCount),
map(count => {
if (count > 0) {
if (count < 5) {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
2019-11-29 16:08:24 +09:00
title: '로그인',
html: `아이디 또는 패스워드가<br/>일치하지 않습니다.`
}
});
}
if (count === 5) {
this.dialogService.open<
AlertDialogComponent,
AlertDialogData,
AlertDialogResult
>(AlertDialogComponent, {
width: '360px',
data: {
2019-11-29 16:08:24 +09:00
title: '로그인',
html: `비밀번호 오류 횟수 초과입니다.<br/>비밀번호를 확인하신 후<br/>잠시 후 다시 시작해 주세요.`
}
});
this.timeChecker = setInterval(() => this.getCheckTime(), 1000);
}
return;
} else {
if (!!this.timeChecker) {
clearInterval(this.timeChecker);
}
this.waitingTime = this.defatulWaitingTime;
this.loginBtnText = this.defatulLoginBtnText;
this.loginBtnEnable = true;
}
})
)
.subscribe();
this.customInitilize();
}
customInitilize() {
// Daesang..
this.fixedCompany = environment.companyConfig.fixedCompanyCode;
this.fixedNotiBtnText = '이용 주의사항';
}
ngOnDestroy(): void {
if (!!this.loginFailureCount) {
this.loginFailureCount.unsubscribe();
}
}
getCheckTime() {
if (this.waitingTime <= 0) {
// reset.
if (!!this.timeChecker) {
clearInterval(this.timeChecker);
}
this.waitingTime = this.defatulWaitingTime;
this.loginBtnText = this.defatulLoginBtnText;
this.loginBtnEnable = true;
} else {
// wait.
this.waitingTime = this.waitingTime - 1;
this.loginBtnText = `${StringUtil.zeroFill(
Math.floor(this.waitingTime / 60),
2
)}:${StringUtil.zeroFill(this.waitingTime % 60, 2)}`;
this.loginBtnEnable = false;
}
2019-09-18 15:02:21 +09:00
}
onLogin(value: {
companyCode: string;
loginId: string;
loginPw: string;
rememberMe: boolean;
2019-12-15 22:49:35 +09:00
autoLogin: boolean;
2019-09-18 15:02:21 +09:00
notValid: () => void;
}) {
this.store.dispatch(
2019-09-24 09:23:30 +09:00
AuthenticationStore.webLogin({
2019-09-18 15:02:21 +09:00
loginInfo: {
companyCode: value.companyCode,
2019-09-27 12:53:21 +09:00
companyGroupType: 'C',
2019-09-18 15:02:21 +09:00
loginId: value.loginId,
loginPw: value.loginPw
},
2019-12-15 22:49:35 +09:00
rememberMe: value.rememberMe,
autoLogin: value.autoLogin
2019-09-18 15:02:21 +09:00
})
);
}
2019-10-02 17:12:51 +09:00
onClickNoti() {
// For Daesang,,
this.dialogService.open<
NoticeDialogComponent,
NoticeDialogData,
NoticeDialogResult
>(NoticeDialogComponent, {
width: '500px',
data: {
title: '이용시 주의사항',
html: `
<p>1. / .</p>
<p>2. ( ) .</p>
<p>3. , , Clean Desk를 .</p>
<p>4. .</p>
<p>5. PC에 .</p>
<p>6. . .</p>
<p>7. ( ) .</p>
`
}
});
2019-10-02 17:12:51 +09:00
}
onClickNextInfomation() {
this.rotateInfomationIndex =
(this.rotateInfomationIndex + 1) % this.rotateInfomation.length;
if (!!this.rotateInfomationIntervalObject) {
clearInterval(this.rotateInfomationIntervalObject);
this.rotateInfomationIntervalObject = setInterval(() => {
this.rotateInfomationIndex =
(this.rotateInfomationIndex + 1) % this.rotateInfomation.length;
}, 8000);
}
}
// onClickTemplate() {
// this.router.navigate(['/template']);
// }
2019-09-18 15:02:21 +09:00
}