BSOne.SFC/eCrmHE/EXE_eCrmHomeEdition/Messages/DOfflineExpAuth.pas

478 lines
12 KiB
Plaintext

unit DOfflineExpAuth;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.ImageList,
Vcl.ImgList, PngImageList, Vcl.Imaging.pngimage, Vcl.ExtCtrls, WindowAnimator;
const
DEF_WIDTH = 397;
EXT_WIDTH = 237;
type
TDlgOfflineAuth = class(TForm)
Label1: TLabel;
btnOk: TButton;
btnCancel: TButton;
edRndCode1: TEdit;
edRndCode2: TEdit;
edRndCode3: TEdit;
edRndCode4: TEdit;
edRndCode5: TEdit;
edRndCode6: TEdit;
Label2: TLabel;
edAuthCode1: TEdit;
edAuthCode2: TEdit;
edAuthCode3: TEdit;
edAuthCode4: TEdit;
edAuthCode5: TEdit;
edAuthCode6: TEdit;
imgArrow: TPngImageList;
imgExpend: TImage;
sbBack: TShape;
chUseExpFun: TCheckBox;
chFun_USB: TCheckBox;
chFun_MTP: TCheckBox;
chFun_BT: TCheckBox;
chFun_CB: TCheckBox;
chFun_WIFI: TCheckBox;
lbExpMin: TLabel;
cbExpMin: TComboBox;
tInit: TTimer;
procedure btnOkClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnCancelClick(Sender: TObject);
procedure edAuthCode6KeyPress(Sender: TObject; var Key: Char);
procedure Label2DblClick(Sender: TObject);
procedure imgExpendClick(Sender: TObject);
procedure imgExpendMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure imgExpendMouseEnter(Sender: TObject);
procedure imgExpendMouseLeave(Sender: TObject);
procedure imgExpendMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure chUseExpFunClick(Sender: TObject);
procedure tInitTimer(Sender: TObject);
procedure edAuthCode1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
sAuth_: String;
nAuthFailCnt_: Integer;
bWndExpend_: Boolean;
WndAni_: TWindowAnimator;
function GetRandomCode: String;
procedure InitCode;
procedure ClearAuthEdit;
procedure SetImgBtn(nImgIdx: Integer);
procedure FinishWindowExpend;
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
procedure CreateParams(var Params: TCreateParams); override; // 작업표시줄에 표시
end;
var
DlgOfflineAuth: TDlgOfflineAuth;
implementation
uses
ManagerService, System.Math, CrmLogger, Tocsg.Strings, GlobalDefine, Tocsg.DateTime;
resourcestring
RS_InputAuth = '인증키를 입력해주십시오.';
RS_InvalidAuth = '유효하지 않은 인증키 입니다.';
RS_NoPolicy = '할당된 예외 정책이 없습니다.';
RS_InsertExcept = '예외 기능 지정이 필요합니다.';
RS_NoPreExcept = '사전 신청하지 않은 예외 적용입니다.';
RS_NoPreExcept2 = '사용할 경우, 사내망 복귀 시 반드시 추가 신청을';
RS_NoPreExcept3 = '상신해야 합니다. 사용 이력 등이 수집됩니다.';
RS_Continue = '계속 하시겠습니까?';
RS_InputCode = '인증코드를 입력해 주십시오.';
RS_ErrorLength = '인증코드 길이 오류입니다.';
RS_Fail3 = '인증을 3회 실패했습니다.';
RS_CodeClear = '인증 및 코드 생성을 초기화 합니다.';
RS_InvalidCode = '유효하지 않은 인증코드입니다. (초기화 : %d)';
{$R *.dfm}
Constructor TDlgOfflineAuth.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
sAuth_ := '';
nAuthFailCnt_ := 0;
WndAni_ := TWindowAnimator.Create(Self);
WndAni_.Duration := 300;
bWndExpend_ := false;
Width := DEF_WIDTH;
imgExpend.Visible := false;
InitCode;
tInit.Enabled := true;
end;
Destructor TDlgOfflineAuth.Destroy;
begin
FreeAndNil(WndAni_);
Inherited;
end;
procedure TDlgOfflineAuth.InitCode;
var
sCode: String;
begin
sCode := GetRandomCode;
ASSERT(sCode.Length = 6);
edRndCode1.Text := sCode[1];
edRndCode2.Text := sCode[2];
edRndCode3.Text := sCode[3];
edRndCode4.Text := sCode[4];
edRndCode5.Text := sCode[5];
edRndCode6.Text := sCode[6];
end;
procedure TDlgOfflineAuth.SetImgBtn(nImgIdx: Integer);
begin
try
imgArrow.GetIcon(nImgIdx, imgExpend.Picture.Icon);
imgExpend.Repaint
except
// ..
end;
end;
procedure TDlgOfflineAuth.tInitTimer(Sender: TObject);
begin
tInit.Enabled := false;
if (gMgSvc.PrefModel.IsOldPolicy and (gMgSvc.PrefModel.ExpPolicy = '')) or
(not gMgSvc.ExpPolicy.Loaded) then
begin
MessageBox(Handle, PChar(RS_NoPolicy+#13+#10+RS_InsertExcept),
PChar(Caption), MB_ICONINFORMATION or MB_OK);
imgExpend.Visible := true;
imgExpendClick(nil);
end;
end;
procedure TDlgOfflineAuth.FinishWindowExpend;
begin
bWndExpend_ := not bWndExpend_;
imgExpendMouseEnter(nil);
imgExpend.Enabled := true;
// 보험
if Width < DEF_WIDTH then
Width := DEF_WIDTH
else if Width > (DEF_WIDTH + EXT_WIDTH) then
Width := DEF_WIDTH + EXT_WIDTH;
end;
procedure TDlgOfflineAuth.Label2DblClick(Sender: TObject);
var
ShiftState: TShiftState;
begin
ShiftState := KeyDataToShiftState(0);
if GetKeyState(VK_LMENU) < 0 then
Include(ShiftState, ssAlt);
if (ssShift in ShiftState) and
(ssAlt in ShiftState) and
(ssCtrl in ShiftState) then
begin
ShowMessage(sAuth_);
end;
end;
procedure TDlgOfflineAuth.chUseExpFunClick(Sender: TObject);
begin
if chUseExpFun.Checked then
begin
if MessageBox(Handle, PChar(RS_NoPreExcept+#13+#10+
RS_NoPreExcept2+#13#10+RS_NoPreExcept3+#13+#10+
RS_Continue), PChar(Caption), MB_ICONWARNING or MB_YESNO) = IDNO then
begin
chUseExpFun.Checked := false;
exit;
end;
end;
chFun_USB.Enabled := chUseExpFun.Checked;
chFun_MTP.Enabled := chUseExpFun.Checked;
chFun_BT.Enabled := chUseExpFun.Checked;
chFun_CB.Enabled := chUseExpFun.Checked;
chFun_WIFI.Enabled := chUseExpFun.Checked;
lbExpMin.Enabled := chUseExpFun.Checked;
cbExpMin.Enabled := chUseExpFun.Checked;
end;
procedure TDlgOfflineAuth.ClearAuthEdit;
begin
edAuthCode1.Text := '';
edAuthCode2.Text := '';
edAuthCode3.Text := '';
edAuthCode4.Text := '';
edAuthCode5.Text := '';
edAuthCode6.Text := '';
end;
procedure TDlgOfflineAuth.CreateParams(var Params: TCreateParams);
begin
Inherited CreateParams(Params);
Params.ExStyle := WS_EX_APPWINDOW;
end;
procedure TDlgOfflineAuth.edAuthCode1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 8 then
begin
if (Sender is TEdit) and (TEdit(Sender).Text = '') then
begin
if Sender = edAuthCode2 then
edAuthCode1.SetFocus
else if Sender = edAuthCode3 then
edAuthCode2.SetFocus
else if Sender = edAuthCode4 then
edAuthCode3.SetFocus
else if Sender = edAuthCode5 then
edAuthCode4.SetFocus
else if Sender = edAuthCode6 then
edAuthCode5.SetFocus;
end;
end else begin
if Sender = edAuthCode1 then
edAuthCode2.SetFocus
else if Sender = edAuthCode2 then
edAuthCode3.SetFocus
else if Sender = edAuthCode3 then
edAuthCode4.SetFocus
else if Sender = edAuthCode4 then
edAuthCode5.SetFocus
else if Sender = edAuthCode5 then
edAuthCode6.SetFocus;
end;
end;
procedure TDlgOfflineAuth.edAuthCode6KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Key := #0;
btnOk.Click;
end;
end;
procedure TDlgOfflineAuth.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
end;
function TDlgOfflineAuth.GetRandomCode: String;
var
i: Integer;
sCode, sAuth, sTemp: String;
dtNow: TDateTime;
Label
LB_CreateCode;
begin
LB_CreateCode :
Randomize;
for i := 0 to 5 do
sCode := sCode + IntToStr(RandomRange(0, 10));
dtNow := ConvLocalToUtc(Now);
sTemp := FormatDateTime('yy', dtNow);
sTemp := sTemp[Length(sTemp)];
sTemp := sTemp + FormatDateTime('mmdd', dtNow);
sTemp := sCode + sTemp + sTemp;
sAuth := EncryptStrToBinStr(sTemp, gMgSvc.EmpNo);
sAuth := ExtrNumStr(sAuth);
if (sCode.Length < 6) or
(gMgSvc.UseOptCodeList.IndexOf(sCode + sAuth) <> -1) then
goto LB_CreateCode;
SetLength(sAuth, 6);
sAuth_ := sAuth;
Result := sCode;
end;
procedure TDlgOfflineAuth.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TDlgOfflineAuth.btnOkClick(Sender: TObject);
var
sAuth: String;
ExpFun: TExpFun;
begin
if edAuthCode1.Text = '' then
begin
MessageBox(Handle, PChar(RS_InputCode), PChar(Caption), MB_ICONWARNING or MB_OK);
edAuthCode1.SetFocus;
exit;
end;
if edAuthCode2.Text = '' then
begin
MessageBox(Handle, PChar(RS_InputCode), PChar(Caption), MB_ICONWARNING or MB_OK);
edAuthCode2.SetFocus;
exit;
end;
if edAuthCode3.Text = '' then
begin
MessageBox(Handle, PChar(RS_InputCode), PChar(Caption), MB_ICONWARNING or MB_OK);
edAuthCode3.SetFocus;
exit;
end;
if edAuthCode4.Text = '' then
begin
MessageBox(Handle, PChar(RS_InputCode), PChar(Caption), MB_ICONWARNING or MB_OK);
edAuthCode4.SetFocus;
exit;
end;
if edAuthCode5.Text = '' then
begin
MessageBox(Handle, PChar(RS_InputCode), PChar(Caption), MB_ICONWARNING or MB_OK);
edAuthCode5.SetFocus;
exit;
end;
if edAuthCode6.Text = '' then
begin
MessageBox(Handle, PChar(RS_InputCode), PChar(Caption), MB_ICONWARNING or MB_OK);
edAuthCode6.SetFocus;
exit;
end;
sAuth := edAuthCode1.Text + edAuthCode2.Text + edAuthCode3.Text +
edAuthCode4.Text + edAuthCode5.Text + edAuthCode6.Text;
if sAuth.Length <> 6 then
begin
MessageBox(Handle, PChar(RS_ErrorLength), PChar(Caption), MB_ICONWARNING or MB_OK);
exit;
end;
if sAuth <> sAuth_ then
begin
if nAuthFailCnt_ = 3 then
begin
nAuthFailCnt_ := 0;
MessageBox(Handle, PChar(RS_Fail3+#13+#10+
RS_CodeClear), PChar(Caption), MB_ICONWARNING or MB_OK);
InitCode;
end else begin
MessageBox(Handle, PChar(Format(RS_InvalidCode, [3 - nAuthFailCnt_])),
PChar(Caption), MB_ICONWARNING or MB_OK);
Inc(nAuthFailCnt_);
end;
ClearAuthEdit;
edAuthCode1.SetFocus;
exit;
end;
ZeroMemory(@ExpFun, SizeOf(ExpFun));
if chUseExpFun.Checked then
begin
ExpFun.bUsb := chFun_USB.Checked;
ExpFun.bMtp := chFun_MTP.Checked;
ExpFun.bBT := chFun_BT.Checked;
ExpFun.bWifi := chFun_WIFI.Checked;
ExpFun.bCB := chFun_CB.Checked;
case cbExpMin.ItemIndex of
1 : ExpFun.nUseMin := 30;
2 : ExpFun.nUseMin := 60;
else ExpFun.nUseMin := 10;
end;
sAuth := Format('%dMin', [ExpFun.nUseMin]);
if ExpFun.bUsb then
SumString(sAuth, 'USB', ', ');
if ExpFun.bMtp then
SumString(sAuth, 'MTP', ', ');
if ExpFun.bBT then
SumString(sAuth, 'Bluetooth', ', ');
if ExpFun.bWifi then
SumString(sAuth, 'WIFI', ', ');
if ExpFun.bCB then
SumString(sAuth, 'Clipboard', ', ');
gMgSvc.SendEventLog(URI_USER_ACTION, SYSEVT_CUSTOMEXPTION, sAuth);
end else begin
if (gMgSvc.PrefModel.IsOldPolicy and (gMgSvc.PrefModel.ExpPolicy = '')) or
(not gMgSvc.ExpPolicy.Loaded) then
begin
MessageBox(Handle, PChar(RS_NoPolicy+#13+#10+RS_InsertExcept),
PChar(Caption), MB_ICONINFORMATION or MB_OK);
if not bWndExpend_ then
imgExpendClick(nil);
exit;
end;
ExpFun.nUseMin := gMgSvc.PrefModel.ExpPoMin;
end;
gMgSvc.SetExpPolicyActive(ExpFun);
Close;
end;
procedure TDlgOfflineAuth.imgExpendClick(Sender: TObject);
begin
imgExpend.Enabled := false;
if not bWndExpend_ then
WndAni_.AnimateWidth(Width + EXT_WIDTH, nil, FinishWindowExpend)
else
WndAni_.AnimateWidth(Width - EXT_WIDTH, nil, FinishWindowExpend);
end;
procedure TDlgOfflineAuth.imgExpendMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if not bWndExpend_ then
SetImgBtn(2)
else
SetImgBtn(5);
end;
procedure TDlgOfflineAuth.imgExpendMouseEnter(Sender: TObject);
begin
if not bWndExpend_ then
SetImgBtn(1)
else
SetImgBtn(4);
end;
procedure TDlgOfflineAuth.imgExpendMouseLeave(Sender: TObject);
begin
if not bWndExpend_ then
SetImgBtn(0)
else
SetImgBtn(3);
end;
procedure TDlgOfflineAuth.imgExpendMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if not bWndExpend_ then
SetImgBtn(1)
else
SetImgBtn(4);
end;
end.