-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
707 lines (601 loc) · 27.6 KB
/
Copy pathmain.py
File metadata and controls
707 lines (601 loc) · 27.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# main.py
import sys
import subprocess
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLineEdit, QPushButton, QLabel, QStackedWidget, QMessageBox, QDialog,
QListView, QFrame, QFormLayout, QTextEdit
)
from PyQt6.QtGui import QFont, QStandardItemModel, QStandardItem
from PyQt6.QtCore import Qt, QPropertyAnimation, QEasingCurve, QRect, QThread, pyqtSignal
# --- 로거 및 핸들러 임포트 ---
from logging_handler import logger
from api_client import APIClient
from smartcard_handler import CardMonitorThread, check_applet, install_applet
from settings_manager import SettingsManager
# --- 전역 API 클라이언트 인스턴스 ---
api_client = APIClient()
class SettingsDialog(QDialog):
"""환경설정을 위한 다이얼로그 클래스"""
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("환경설정")
self.setFixedSize(500, 400)
self.setModal(True)
self.settings_manager = SettingsManager()
self.init_ui()
self.load_current_settings()
logger.info("환경설정 다이얼로그 생성됨.")
def init_ui(self):
"""환경설정 UI 초기화"""
layout = QVBoxLayout(self)
layout.setContentsMargins(20, 20, 20, 20)
layout.setSpacing(15)
title_label = QLabel("GlobalPlatform 키 설정")
title_label.setFont(QFont("Inter", 16, QFont.Weight.Bold))
title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
form_layout = QFormLayout()
form_layout.setSpacing(10)
# DEK 키 입력
self.key_dek_input = QLineEdit()
self.key_dek_input.setFont(QFont("Consolas", 10))
self.key_dek_input.setPlaceholderText("DEK 키 (32자리 16진수)")
form_layout.addRow("Key DEK:", self.key_dek_input)
# ENC 키 입력
self.key_enc_input = QLineEdit()
self.key_enc_input.setFont(QFont("Consolas", 10))
self.key_enc_input.setPlaceholderText("ENC 키 (32자리 16진수)")
form_layout.addRow("Key ENC:", self.key_enc_input)
# MAC 키 입력
self.key_mac_input = QLineEdit()
self.key_mac_input.setFont(QFont("Consolas", 10))
self.key_mac_input.setPlaceholderText("MAC 키 (32자리 16진수)")
form_layout.addRow("Key MAC:", self.key_mac_input)
# 버튼 레이아웃
button_layout = QHBoxLayout()
save_button = QPushButton("저장")
save_button.setFont(QFont("Inter", 11, QFont.Weight.Bold))
save_button.setFixedHeight(40)
save_button.clicked.connect(self.save_settings)
save_button.setStyleSheet("""
QPushButton {
background-color: #28a745; color: white; border-radius: 5px;
}
QPushButton:hover { background-color: #218838; }
""")
reset_button = QPushButton("기본값으로 재설정")
reset_button.setFont(QFont("Inter", 11))
reset_button.setFixedHeight(40)
reset_button.clicked.connect(self.reset_to_defaults)
reset_button.setStyleSheet("""
QPushButton {
background-color: #6c757d; color: white; border-radius: 5px;
}
QPushButton:hover { background-color: #5a6268; }
""")
cancel_button = QPushButton("취소")
cancel_button.setFont(QFont("Inter", 11))
cancel_button.setFixedHeight(40)
cancel_button.clicked.connect(self.reject)
cancel_button.setStyleSheet("""
QPushButton {
background-color: #dc3545; color: white; border-radius: 5px;
}
QPushButton:hover { background-color: #c82333; }
""")
button_layout.addWidget(reset_button)
button_layout.addStretch()
button_layout.addWidget(cancel_button)
button_layout.addWidget(save_button)
layout.addWidget(title_label)
layout.addLayout(form_layout)
layout.addStretch()
layout.addLayout(button_layout)
def load_current_settings(self):
"""현재 설정값들을 UI에 로드"""
keys = self.settings_manager.get_all_keys()
self.key_dek_input.setText(keys.get("key_dek", ""))
self.key_enc_input.setText(keys.get("key_enc", ""))
self.key_mac_input.setText(keys.get("key_mac", ""))
def validate_key(self, key_value):
"""키 값 유효성 검증"""
if len(key_value) != 32:
return False
try:
int(key_value, 16)
return True
except ValueError:
return False
def save_settings(self):
"""설정값 저장"""
key_dek = self.key_dek_input.text().strip().upper()
key_enc = self.key_enc_input.text().strip().upper()
key_mac = self.key_mac_input.text().strip().upper()
# 유효성 검증
if not self.validate_key(key_dek):
QMessageBox.warning(self, "입력 오류", "DEK 키는 32자리 16진수여야 합니다.")
return
if not self.validate_key(key_enc):
QMessageBox.warning(self, "입력 오류", "ENC 키는 32자리 16진수여야 합니다.")
return
if not self.validate_key(key_mac):
QMessageBox.warning(self, "입력 오류", "MAC 키는 32자리 16진수여야 합니다.")
return
# 설정 저장
new_keys = {
"key_dek": key_dek,
"key_enc": key_enc,
"key_mac": key_mac
}
if self.settings_manager.save_settings(new_keys):
QMessageBox.information(self, "저장 완료", "설정이 성공적으로 저장되었습니다.")
self.accept()
else:
QMessageBox.critical(self, "저장 실패", "설정 저장 중 오류가 발생했습니다.")
def reset_to_defaults(self):
"""기본값으로 재설정"""
reply = QMessageBox.question(
self, "기본값 재설정",
"모든 키를 기본값으로 재설정하시겠습니까?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)
if reply == QMessageBox.StandardButton.Yes:
defaults = self.settings_manager.DEFAULT_KEYS
self.key_dek_input.setText(defaults["key_dek"])
self.key_enc_input.setText(defaults["key_enc"])
self.key_mac_input.setText(defaults["key_mac"])
class RegisterUserDialog(QDialog):
"""카드 발급을 위한 팝업 다이얼로그 클래스"""
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("카드 발급")
self.setFixedSize(400, 250)
self.setModal(True)
self.emp_no = ""
self.card_monitor_thread = None
self.stacked_widget = QStackedWidget(self)
self.init_emp_no_ui()
self.init_card_tag_ui()
main_layout = QVBoxLayout(self)
main_layout.addWidget(self.stacked_widget)
self.setLayout(main_layout)
logger.info("카드 발급 다이얼로그 생성됨.")
def init_emp_no_ui(self):
"""사번 입력 UI 초기화"""
widget = QWidget()
layout = QVBoxLayout(widget)
layout.setContentsMargins(20, 20, 20, 20)
layout.setSpacing(15)
title_label = QLabel("발급할 사용자의 사번을 입력하세요.")
title_label.setFont(QFont("Inter", 12))
title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.emp_no_input = QLineEdit()
self.emp_no_input.setPlaceholderText("사원 번호")
self.emp_no_input.setFont(QFont("Inter", 11))
self.emp_no_input.setFixedHeight(40)
self.confirm_button = QPushButton("확인")
self.confirm_button.setFont(QFont("Inter", 11, QFont.Weight.Bold))
self.confirm_button.setFixedHeight(45)
self.confirm_button.clicked.connect(self.start_card_process)
self.confirm_button.setStyleSheet("""
QPushButton {
background-color: #3498db; color: white; border-radius: 5px;
}
QPushButton:hover { background-color: #2980b9; }
""")
layout.addWidget(title_label)
layout.addWidget(self.emp_no_input)
layout.addWidget(self.confirm_button)
layout.addStretch(1)
widget.setLayout(layout)
self.stacked_widget.addWidget(widget)
def init_card_tag_ui(self):
"""카드 태깅 대기 UI 초기화"""
widget = QWidget()
layout = QVBoxLayout(widget)
layout.setContentsMargins(20, 20, 20, 20)
layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
message_label = QLabel("스마트카드를 리더기에 태그해주세요...")
message_label.setFont(QFont("Inter", 12, QFont.Weight.Bold))
message_label.setWordWrap(True)
message_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(message_label)
widget.setLayout(layout)
self.stacked_widget.addWidget(widget)
def start_card_process(self):
"""'확인' 버튼 클릭 시 카드 처리 프로세스 시작"""
self.emp_no = self.emp_no_input.text().strip()
if not self.emp_no:
QMessageBox.warning(self, "입력 오류", "사번을 입력해주세요.")
logger.warning("사번이 입력되지 않은 상태로 '확인' 버튼 클릭됨.")
return
logger.info(f"사번 '{self.emp_no}'에 대한 카드 등록 절차 시작.")
self.stacked_widget.setCurrentIndex(1)
self.card_monitor_thread = CardMonitorThread()
self.card_monitor_thread.card_detected.connect(self.handle_card_detected)
self.card_monitor_thread.no_reader.connect(self.handle_no_reader)
self.card_monitor_thread.start()
def handle_no_reader(self):
"""카드 리더기 없음 처리"""
logger.error("스마트카드 리더기를 찾을 수 없음.")
QMessageBox.critical(self, "오류", "스마트카드 리더기가 연결되어 있지 않습니다.")
self.close()
def handle_card_detected(self):
"""카드 감지 시 처리 로직"""
logger.info("스마트카드가 감지됨.")
try:
is_installed = check_applet()
if is_installed:
logger.info("이미 애플릿이 설치된 카드가 감지됨.")
QMessageBox.information(self, "알림", "이미 애플릿이 설치된 카드입니다.")
self.close()
return
success, message = install_applet(self.emp_no)
if success:
logger.info(f"사번 '{self.emp_no}'의 애플릿 설치 성공.")
QMessageBox.information(self, "성공", f"애플릿 설치에 성공했습니다.")
else:
logger.error(f"사번 '{self.emp_no}'의 애플릿 설치 실패. 원인: {message}")
QMessageBox.critical(self, "실패", f"애플릿 설치에 실패했습니다.\n로그를 확인해주세요.")
except Exception as e:
logger.critical(f"카드 처리 중 예외 발생: {e}", exc_info=True)
QMessageBox.critical(self, "오류", f"카드 처리 중 오류가 발생했습니다: {e}")
finally:
self.close()
def closeEvent(self, event):
"""다이얼로그 종료 시 스레드 정리"""
logger.info("카드 발급 다이얼로그 닫힘.")
if self.card_monitor_thread and self.card_monitor_thread.isRunning():
self.card_monitor_thread.stop()
self.card_monitor_thread.wait()
super().closeEvent(event)
class MainWindow(QMainWindow):
"""메인 윈도우 클래스"""
def __init__(self):
super().__init__()
self.setWindowTitle("OneCard 발급 프로그램")
self.setGeometry(100, 100, 600, 800)
self.stacked_widget = QStackedWidget()
self.setCentralWidget(self.stacked_widget)
self.login_widget = self.create_login_ui()
self.main_widget = self.create_main_ui()
self.settings_widget = self.create_settings_ui()
self.stacked_widget.addWidget(self.login_widget)
self.stacked_widget.addWidget(self.main_widget)
self.stacked_widget.addWidget(self.settings_widget)
self.animation = None
self.load_styles()
logger.info("메인 윈도우 생성 및 초기화 완료.")
def load_styles(self):
"""전체 애플리케이션 스타일시트 적용"""
self.setStyleSheet("""
QMainWindow, QWidget {
background-color: #ecf0f1;
font-family: 'Inter';
}
QLineEdit {
border: 1px solid #bdc3c7;
padding: 10px;
border-radius: 5px;
background-color: white;
}
QPushButton {
border: none;
padding: 10px;
border-radius: 5px;
color: white;
font-weight: bold;
}
QLabel {
color: #2c3e50;
}
""")
def create_login_ui(self):
"""로그인 화면 UI 생성"""
widget = QWidget()
main_layout = QVBoxLayout(widget)
main_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
login_box = QFrame()
login_box.setFrameShape(QFrame.Shape.StyledPanel)
login_box.setFixedWidth(400)
login_box.setFixedHeight(450)
login_box.setStyleSheet("background-color: #ffffff; border-radius: 10px;")
layout = QVBoxLayout(login_box)
layout.setContentsMargins(40, 40, 40, 40)
layout.setSpacing(20)
title = QLabel("관리자 로그인")
title.setFont(QFont("Inter", 20, QFont.Weight.Bold))
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.username_input = QLineEdit()
self.username_input.setPlaceholderText("사용자명")
self.username_input.setFont(QFont("Inter", 12))
self.username_input.setFixedHeight(50)
self.password_input = QLineEdit()
self.password_input.setPlaceholderText("비밀번호")
self.password_input.setEchoMode(QLineEdit.EchoMode.Password)
self.password_input.setFont(QFont("Inter", 12))
self.password_input.setFixedHeight(50)
self.password_input.returnPressed.connect(self.attempt_login) # 엔터키 지원
login_button = QPushButton("로그인")
login_button.setFixedHeight(50)
login_button.setFont(QFont("Inter", 12, QFont.Weight.Bold))
login_button.setStyleSheet("""
QPushButton { background-color: #3498db; }
QPushButton:hover { background-color: #2980b9; }
""")
login_button.clicked.connect(self.attempt_login)
layout.addWidget(title)
layout.addSpacing(20)
layout.addWidget(self.username_input)
layout.addWidget(self.password_input)
layout.addSpacing(10)
layout.addWidget(login_button)
main_layout.addWidget(login_box)
return widget
def create_main_ui(self):
"""메인 화면 UI 생성"""
widget = QWidget()
layout = QVBoxLayout(widget)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
# 상단 타이틀 영역
title_area = QWidget()
title_area.setStyleSheet("background-color: #ffffff; padding: 40px;")
title_layout = QVBoxLayout(title_area)
title_label = QLabel("OneCard 발급 프로그램")
title_label.setFont(QFont("Inter", 24, QFont.Weight.Bold))
title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
title_label.setStyleSheet("color: #2c3e50; margin-bottom: 10px;")
subtitle_label = QLabel("스마트카드 발급 및 관리")
subtitle_label.setFont(QFont("Inter", 14))
subtitle_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
subtitle_label.setStyleSheet("color: #7f8c8d;")
title_layout.addWidget(title_label)
title_layout.addWidget(subtitle_label)
# 중앙 버튼 영역
button_area = QWidget()
button_area.setStyleSheet("background-color: #ecf0f1;")
button_layout = QVBoxLayout(button_area)
button_layout.setContentsMargins(60, 60, 60, 60)
button_layout.setSpacing(20)
# 카드 발급 버튼
issue_button = QPushButton("카드 발급")
issue_button.setFont(QFont("Inter", 16, QFont.Weight.Bold))
issue_button.setFixedHeight(80)
issue_button.setStyleSheet("""
QPushButton {
background-color: #3498db;
color: white;
border-radius: 10px;
padding: 20px;
}
QPushButton:hover { background-color: #2980b9; }
""")
issue_button.clicked.connect(self.open_register_dialog)
# 환경설정 버튼
settings_button = QPushButton("환경설정")
settings_button.setFont(QFont("Inter", 16, QFont.Weight.Bold))
settings_button.setFixedHeight(80)
settings_button.setStyleSheet("""
QPushButton {
background-color: #95a5a6;
color: white;
border-radius: 10px;
padding: 20px;
}
QPushButton:hover { background-color: #7f8c8d; }
""")
settings_button.clicked.connect(self.show_settings)
button_layout.addWidget(issue_button)
button_layout.addWidget(settings_button)
button_layout.addStretch()
layout.addWidget(title_area)
layout.addWidget(button_area)
return widget
def create_settings_ui(self):
"""환경설정 화면 UI 생성"""
widget = QWidget()
layout = QVBoxLayout(widget)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
# 상단 헤더
header = QWidget()
header.setStyleSheet("background-color: #34495e; padding: 20px;")
header_layout = QHBoxLayout(header)
back_button = QPushButton("← 뒤로")
back_button.setFont(QFont("Inter", 12))
back_button.setStyleSheet("""
QPushButton {
background-color: #95a5a6;
color: white;
border-radius: 5px;
padding: 10px 20px;
}
QPushButton:hover { background-color: #7f8c8d; }
""")
back_button.clicked.connect(self.show_main_form)
title_label = QLabel("환경설정")
title_label.setFont(QFont("Inter", 18, QFont.Weight.Bold))
title_label.setStyleSheet("color: white;")
title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
header_layout.addWidget(back_button)
header_layout.addWidget(title_label)
header_layout.addStretch()
# 설정 내용 영역
content_area = QWidget()
content_area.setStyleSheet("background-color: #ecf0f1; padding: 40px;")
content_layout = QVBoxLayout(content_area)
self.settings_manager = SettingsManager()
# GP 키 설정 폼
form_layout = QFormLayout()
form_layout.setSpacing(15)
form_layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
form_layout.setLabelAlignment(Qt.AlignmentFlag.AlignVCenter)
# DEK 키 입력
dek_label = QLabel("Key DEK:")
dek_label.setFont(QFont("Inter", 12, QFont.Weight.Bold))
dek_label.setAlignment(Qt.AlignmentFlag.AlignVCenter)
self.key_dek_input = QLineEdit()
self.key_dek_input.setFont(QFont("Consolas", 11))
self.key_dek_input.setFixedHeight(40)
self.key_dek_input.setPlaceholderText("DEK 키 (32자리 16진수)")
form_layout.addRow(dek_label, self.key_dek_input)
# ENC 키 입력
enc_label = QLabel("Key ENC:")
enc_label.setFont(QFont("Inter", 12, QFont.Weight.Bold))
enc_label.setAlignment(Qt.AlignmentFlag.AlignVCenter)
self.key_enc_input = QLineEdit()
self.key_enc_input.setFont(QFont("Consolas", 11))
self.key_enc_input.setFixedHeight(40)
self.key_enc_input.setPlaceholderText("ENC 키 (32자리 16진수)")
form_layout.addRow(enc_label, self.key_enc_input)
# MAC 키 입력
mac_label = QLabel("Key MAC:")
mac_label.setFont(QFont("Inter", 12, QFont.Weight.Bold))
mac_label.setAlignment(Qt.AlignmentFlag.AlignVCenter)
self.key_mac_input = QLineEdit()
self.key_mac_input.setFont(QFont("Consolas", 11))
self.key_mac_input.setFixedHeight(40)
self.key_mac_input.setPlaceholderText("MAC 키 (32자리 16진수)")
form_layout.addRow(mac_label, self.key_mac_input)
# 버튼 레이아웃
button_layout = QHBoxLayout()
save_button = QPushButton("저장")
save_button.setFont(QFont("Inter", 14, QFont.Weight.Bold))
save_button.setFixedHeight(50)
save_button.clicked.connect(self.save_gp_settings)
save_button.setStyleSheet("""
QPushButton {
background-color: #28a745; color: white; border-radius: 5px;
font-weight: bold;
}
QPushButton:hover { background-color: #218838; color: white; }
""")
reset_button = QPushButton("기본값으로 재설정")
reset_button.setFont(QFont("Inter", 14))
reset_button.setFixedHeight(50)
reset_button.clicked.connect(self.reset_gp_settings)
reset_button.setStyleSheet("""
QPushButton {
background-color: #6c757d; color: white; border-radius: 5px;
font-weight: bold;
}
QPushButton:hover { background-color: #5a6268; color: white; }
""")
button_layout.addWidget(reset_button)
button_layout.addStretch()
button_layout.addWidget(save_button)
content_layout.addLayout(form_layout)
content_layout.addStretch()
content_layout.addLayout(button_layout)
layout.addWidget(header)
layout.addWidget(content_area)
return widget
def attempt_login(self):
"""로그인 시도"""
username = self.username_input.text()
password = self.password_input.text()
logger.info(f"사용자 '{username}' 로그인 시도.")
if not username or not password:
QMessageBox.warning(self, "로그인 실패", "사용자명과 비밀번호를 모두 입력해주세요.")
logger.warning("사용자명 또는 비밀번호가 입력되지 않은 상태로 로그인 시도.")
return
try:
response = api_client.login(username, password)
if "access_token" in response:
logger.info(f"사용자 '{username}' 로그인 성공.")
self.show_main_form()
else:
error_msg = response.get("detail", "알 수 없는 오류가 발생했습니다.")
logger.error(f"사용자 '{username}' 로그인 실패. 원인: {error_msg}")
QMessageBox.critical(self, "로그인 실패", str(error_msg))
except Exception as e:
logger.critical(f"로그인 중 서버 연결 오류 발생: {e}", exc_info=True)
QMessageBox.critical(self, "연결 오류", f"서버에 연결할 수 없습니다: {e}")
def show_main_form(self):
"""애니메이션과 함께 메인 화면으로 전환"""
logger.info("메인 화면으로 전환 시작.")
current_widget = self.stacked_widget.currentWidget()
next_widget = self.main_widget
self.stacked_widget.setCurrentWidget(next_widget)
next_widget.setGeometry(self.width(), 0, self.width(), self.height())
self.animation = QPropertyAnimation(next_widget, b"geometry")
self.animation.setDuration(500)
self.animation.setStartValue(QRect(self.width(), 0, self.width(), self.height()))
self.animation.setEndValue(QRect(0, 0, self.width(), self.height()))
self.animation.setEasingCurve(QEasingCurve.Type.InOutCubic)
self.animation.start()
logger.info("메인 화면으로 전환 완료.")
def show_settings(self):
"""환경설정 화면으로 전환"""
logger.info("환경설정 화면으로 전환 시작.")
self.load_gp_settings() # 현재 설정값 로드
self.stacked_widget.setCurrentWidget(self.settings_widget)
logger.info("환경설정 화면으로 전환 완료.")
def load_gp_settings(self):
"""현재 GP 설정값들을 UI에 로드"""
keys = self.settings_manager.get_all_keys()
self.key_dek_input.setText(keys.get("key_dek", ""))
self.key_enc_input.setText(keys.get("key_enc", ""))
self.key_mac_input.setText(keys.get("key_mac", ""))
def validate_key(self, key_value):
"""키 값 유효성 검증"""
if len(key_value) != 32:
return False
try:
int(key_value, 16)
return True
except ValueError:
return False
def save_gp_settings(self):
"""GP 설정값 저장"""
key_dek = self.key_dek_input.text().strip().upper()
key_enc = self.key_enc_input.text().strip().upper()
key_mac = self.key_mac_input.text().strip().upper()
# 유효성 검증
if not self.validate_key(key_dek):
QMessageBox.warning(self, "입력 오류", "DEK 키는 32자리 16진수여야 합니다.")
return
if not self.validate_key(key_enc):
QMessageBox.warning(self, "입력 오류", "ENC 키는 32자리 16진수여야 합니다.")
return
if not self.validate_key(key_mac):
QMessageBox.warning(self, "입력 오류", "MAC 키는 32자리 16진수여야 합니다.")
return
# 설정 저장
new_keys = {
"key_dek": key_dek,
"key_enc": key_enc,
"key_mac": key_mac
}
if self.settings_manager.save_settings(new_keys):
QMessageBox.information(self, "저장 완료", "설정이 성공적으로 저장되었습니다.")
logger.info("GP 키 설정이 저장되었습니다.")
else:
QMessageBox.critical(self, "저장 실패", "설정 저장 중 오류가 발생했습니다.")
def reset_gp_settings(self):
"""GP 설정을 기본값으로 재설정"""
reply = QMessageBox.question(
self, "기본값 재설정",
"모든 키를 기본값으로 재설정하시겠습니까?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)
if reply == QMessageBox.StandardButton.Yes:
defaults = self.settings_manager.DEFAULT_KEYS
self.key_dek_input.setText(defaults["key_dek"])
self.key_enc_input.setText(defaults["key_enc"])
self.key_mac_input.setText(defaults["key_mac"])
logger.info("GP 키 설정이 기본값으로 재설정되었습니다.")
def open_register_dialog(self):
"""카드 발급 다이얼로그 열기"""
logger.info("'카드 발급' 버튼 클릭됨.")
dialog = RegisterUserDialog(self)
dialog.exec()
if __name__ == "__main__":
logger.info("="*20 + " 애플리케이션 시작 " + "="*20)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
exit_code = app.exec()
logger.info(f"애플리케이션 종료. 종료 코드: {exit_code}")
sys.exit(exit_code)