561 lines
27 KiB
Python
561 lines
27 KiB
Python
from werkzeug.security import check_password_hash
|
|
from PyQt5.QtCore import Qt, QSettings
|
|
from PyQt5 import QtWidgets, QtCore, QtWidgets
|
|
from datetime import datetime
|
|
from credentials import load_credentials, save_credentials
|
|
from src.toggleSwitch import ToggleSwitch # toggle_switch.py에서 ToggleSwitch 클래스를 import
|
|
|
|
import sys
|
|
import logging
|
|
|
|
# 로거 인스턴스 가져오기
|
|
logger = logging.getLogger('default_logger')
|
|
class LoginWidget(QtWidgets.QWidget):
|
|
def __init__(self, mongo_config, CURRENT_VERSION):
|
|
super().__init__()
|
|
self.CURRENT_VERSION = CURRENT_VERSION
|
|
self.mongoConfig = mongo_config
|
|
self.client = mongo_config.client
|
|
|
|
# self.login_db = self.mongoConfig.get_db() # mongo_config 인스턴스를 통해 데이터베이스 객체를 가져옴
|
|
self.login_db = self.client['taobao_project']
|
|
self.initUI()
|
|
# Initialize MongoDB client and select database
|
|
self.loadSettings()
|
|
self.master_email = "로그인 하세요"
|
|
self.result = False
|
|
|
|
self.per_email = None
|
|
self.per_password = None
|
|
self.per_em_email = None
|
|
self.per_em_password = None
|
|
self.per_mode = False
|
|
self.set_num_modify = 0
|
|
|
|
self.alwaysOnTopSwitch = True
|
|
self.whether_shutdownAfterComplete = False
|
|
self.whether_modifyProductName = False
|
|
self.whether_modifyProductOptions = True
|
|
self.whether_modifyProductTag = True
|
|
self.whether_modifyProductPrice = False
|
|
self.whether_modifyProductThumb = True
|
|
self.whether_modifyProductDetail = True
|
|
self.whether_modifyImageTanslation = False
|
|
self.whether_uploadToMarket = False
|
|
|
|
|
|
self.check_for_updates(self.login_db, self.CURRENT_VERSION)
|
|
|
|
|
|
def initUI(self):
|
|
# self.setGeometry(780, 420, 240, 200)
|
|
|
|
# 위젯의 크기를 설정합니다.
|
|
self.resize(800, 800)
|
|
self.center() # 화면 가운데에 위치시키는 메서드
|
|
|
|
# 레이아웃 설정
|
|
layout = QtWidgets.QHBoxLayout()
|
|
|
|
login_info_frame = QtWidgets.QFrame()
|
|
login_layout = QtWidgets.QVBoxLayout()
|
|
login_info_frame.setLayout(login_layout)
|
|
|
|
# 선택사항 영역
|
|
setting_frame = QtWidgets.QFrame()
|
|
setting_layout = QtWidgets.QVBoxLayout()
|
|
setting_frame.setLayout(setting_layout)
|
|
|
|
# 레이아웃 설정
|
|
layout.addWidget(login_info_frame)
|
|
layout.addWidget(setting_frame)
|
|
|
|
self.signupButton = QtWidgets.QPushButton("회원 가입")
|
|
self.signupButton.clicked.connect(self.showSignUpWindow)
|
|
|
|
self.infoLabel = QtWidgets.QLabel("로그인 정보를 입력하세요")
|
|
|
|
self.emailInput = QtWidgets.QLineEdit()
|
|
self.emailInput.setPlaceholderText("서버인증 사용자 이름(이메일형식)")
|
|
self.emailInput.returnPressed.connect(self.focusToPassword) # 사용자 이름에서 엔터 -> 암호칸으로 포커스
|
|
|
|
self.passwordInput = QtWidgets.QLineEdit()
|
|
self.passwordInput.setPlaceholderText("서버인증 비밀번호")
|
|
self.passwordInput.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
self.passwordInput.returnPressed.connect(self.login) # 암호에서 엔터 -> 로그인 시도
|
|
|
|
self.infoLabel2 = QtWidgets.QLabel("========퍼센티 로그인 정보 입력========")
|
|
|
|
self.per_emailInput = QtWidgets.QLineEdit()
|
|
self.per_emailInput.setPlaceholderText("퍼센티 사용자 이름(이메일형식)")
|
|
# self.per_emailInput.returnPressed.connect(self.focusToPassword) # 사용자 이름에서 엔터 -> 암호칸으로 포커스
|
|
|
|
self.per_em_emailInput = QtWidgets.QLineEdit()
|
|
self.per_em_emailInput.setPlaceholderText("퍼센티 직원 아이디")
|
|
# self.per_em_emailInput.returnPressed.connect(self.focusToPassword) # 사용자 이름에서 엔터 -> 암호칸으로 포커스
|
|
|
|
self.per_em_passwordInput = QtWidgets.QLineEdit()
|
|
self.per_em_passwordInput.setPlaceholderText("퍼센티 직원 비밀번호")
|
|
self.per_em_passwordInput.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
# self.per_passwordInput.returnPressed.connect(self.login) # 암호에서 엔터 -> 로그인 시도
|
|
|
|
self.per_passwordInput = QtWidgets.QLineEdit()
|
|
self.per_passwordInput.setPlaceholderText("퍼센티 비밀번호")
|
|
self.per_passwordInput.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
# self.per_passwordInput.returnPressed.connect(self.login) # 암호에서 엔터 -> 로그인 시도
|
|
|
|
self.infoLabel3 = QtWidgets.QLabel("=====================================")
|
|
|
|
# 토글 버튼 추가
|
|
self.changeModeButton = QtWidgets.QPushButton("관리자용 모드")
|
|
self.changeModeButton.setCheckable(True)
|
|
self.changeModeButton.clicked.connect(self.toggleMode)
|
|
# 초기 토글 상태 설정
|
|
self.toggleMode(False)
|
|
|
|
self.set_num_modifyInput = QtWidgets.QLineEdit()
|
|
self.set_num_modifyInput.setPlaceholderText("수정갯수 : 0이면 등록된 모든 신규상품 수정")
|
|
# self.per_em_emailInput.returnPressed.connect(self.focusToPassword) # 사용자 이름에서 엔터 -> 암호칸으로 포커스
|
|
self.infoLabel5 = QtWidgets.QLabel("[수정갯수가 0이면 등록된 모든 신규상품 수정]")
|
|
|
|
# 비밀번호 표시 토글 버튼
|
|
self.showPasswordCheckBox = QtWidgets.QCheckBox("비밀번호 표시")
|
|
self.showPasswordCheckBox.stateChanged.connect(self.togglePasswordVisibility)
|
|
|
|
self.loginButton = QtWidgets.QPushButton("로그인")
|
|
self.loginButton.clicked.connect(self.login)
|
|
|
|
self.alwaysOnTopSwitch = ToggleSwitch(self)
|
|
self.alwaysOnTopSwitch.move(10, 10)
|
|
self.alwaysOnTopSwitch.setChecked(True) # 기본 상태는 ON
|
|
self.alwaysOnTopSwitch.clicked.connect(self.toggleAlwaysOnTop)
|
|
self.alwaysOnTopSwitch_layout = self.create_label_and_switch("항상 위에 표시", self.alwaysOnTopSwitch)
|
|
|
|
self.shutdownSwitch = ToggleSwitch(self)
|
|
self.shutdownSwitch.move(10, 50)
|
|
self.shutdownSwitch.setChecked(False) # 기본 상태는 OFF
|
|
self.shutdownSwitch.clicked.connect(self.shutdownAfterComplete)
|
|
self.shutdownSwitch_layout = self.create_label_and_switch("작업 종료 후 PC 종료", self.shutdownSwitch)
|
|
|
|
|
|
self.modifyProductNameSwitch = ToggleSwitch(self)
|
|
self.modifyProductNameSwitch.move(10, 90)
|
|
self.modifyProductNameSwitch.setChecked(False) # 기본 상태는 OFF
|
|
self.modifyProductNameSwitch.clicked.connect(self.modifyProductName)
|
|
self.modifyProductNameSwitch_layout = self.create_label_and_switch("상품명 수정", self.modifyProductNameSwitch)
|
|
|
|
|
|
self.modifyProductOptionsSwitch = ToggleSwitch(self)
|
|
self.modifyProductOptionsSwitch.move(10, 90)
|
|
self.modifyProductOptionsSwitch.setChecked(True) # 기본 상태는 OFF
|
|
self.modifyProductOptionsSwitch.clicked.connect(self.modifyProductOptions)
|
|
self.modifyProductOptionsSwitch_layout = self.create_label_and_switch("옵션명 수정", self.modifyProductOptionsSwitch)
|
|
|
|
|
|
self.modifyProductTagSwitch = ToggleSwitch(self)
|
|
self.modifyProductTagSwitch.move(10, 90)
|
|
self.modifyProductTagSwitch.setChecked(True) # 기본 상태는 OFF
|
|
self.modifyProductTagSwitch.clicked.connect(self.modifyProductTag)
|
|
self.modifyProductTagSwitch_layout = self.create_label_and_switch("태그 수정", self.modifyProductTagSwitch)
|
|
|
|
|
|
self.modifyProductPriceSwitch = ToggleSwitch(self)
|
|
self.modifyProductPriceSwitch.move(10, 90)
|
|
self.modifyProductPriceSwitch.setChecked(False) # 기본 상태는 OFF
|
|
self.modifyProductPriceSwitch.clicked.connect(self.modifyProductPrice)
|
|
self.modifyProductPriceSwitch_layout = self.create_label_and_switch("가격 수정", self.modifyProductPriceSwitch)
|
|
|
|
|
|
self.modifyProductThumbSwitch = ToggleSwitch(self)
|
|
self.modifyProductThumbSwitch.move(10, 90)
|
|
self.modifyProductThumbSwitch.setChecked(True) # 기본 상태는 OFF
|
|
self.modifyProductThumbSwitch.clicked.connect(self.modifyProductThumb)
|
|
self.modifyProductThumbSwitch_layout = self.create_label_and_switch("썸네일 수정", self.modifyProductThumbSwitch)
|
|
|
|
|
|
self.modifyProductDetailSwitch = ToggleSwitch(self)
|
|
self.modifyProductDetailSwitch.move(10, 90)
|
|
self.modifyProductDetailSwitch.setChecked(True) # 기본 상태는 OFF
|
|
self.modifyProductDetailSwitch.clicked.connect(self.modifyProductDetail)
|
|
self.modifyProductDetailSwitch_layout = self.create_label_and_switch("상세페이지 수정", self.modifyProductDetailSwitch)
|
|
|
|
|
|
self.modifyImageTranslationSwitch = ToggleSwitch(self)
|
|
self.modifyImageTranslationSwitch.move(10, 90)
|
|
self.modifyImageTranslationSwitch.setChecked(False) # 기본 상태는 OFF
|
|
self.modifyImageTranslationSwitch.clicked.connect(self.modifyImageTranslation)
|
|
self.modifyImageTranslationSwitch_layout = self.create_label_and_switch("이미지 번역", self.modifyImageTranslationSwitch)
|
|
|
|
|
|
self.uploadToMarketSwitch = ToggleSwitch(self)
|
|
self.uploadToMarketSwitch.move(10, 90)
|
|
self.uploadToMarketSwitch.setChecked(False) # 기본 상태는 OFF
|
|
self.uploadToMarketSwitch.clicked.connect(self.uploadToMarket)
|
|
self.uploadToMarketSwitch_layout = self.create_label_and_switch("마켓 업로드", self.uploadToMarketSwitch)
|
|
|
|
self.infoLabel4 = QtWidgets.QLabel(" 퍼센티 자동화 by 리앤수Int.")
|
|
|
|
|
|
login_layout.addWidget(self.infoLabel)
|
|
|
|
login_layout.addWidget(self.signupButton)
|
|
login_layout.addWidget(self.infoLabel)
|
|
login_layout.addWidget(self.emailInput)
|
|
login_layout.addWidget(self.passwordInput)
|
|
login_layout.addWidget(self.infoLabel2)
|
|
login_layout.addWidget(self.per_emailInput)
|
|
login_layout.addWidget(self.per_em_emailInput)
|
|
login_layout.addWidget(self.per_em_passwordInput)
|
|
login_layout.addWidget(self.per_passwordInput)
|
|
login_layout.addWidget(self.changeModeButton)
|
|
login_layout.addWidget(self.set_num_modifyInput)
|
|
login_layout.addWidget(self.infoLabel5)
|
|
login_layout.addWidget(self.infoLabel3)
|
|
login_layout.addWidget(self.showPasswordCheckBox)
|
|
login_layout.addWidget(self.loginButton)
|
|
login_layout.addWidget(self.infoLabel4)
|
|
|
|
# labels = ["항상 위", "작업완료 후 PC종료", "상품명 수정", "옵션 수정", "가격 수정", "태그 수정", "썸네일 수정", "상세페이지 수정", "이미지 번역", "마켓 업로드"]
|
|
# for i, label_text in enumerate(labels, start = 1):
|
|
# label = QtWidgets.QLabel(label_text)
|
|
# setting_layout.addWidget(label) # 설명 라벨은 2열(인덱스 1)에 배치
|
|
|
|
setting_layout.addLayout(self.modifyProductNameSwitch_layout)
|
|
setting_layout.addLayout(self.modifyProductOptionsSwitch_layout)
|
|
setting_layout.addLayout(self.modifyProductPriceSwitch_layout)
|
|
setting_layout.addLayout(self.modifyProductTagSwitch_layout)
|
|
setting_layout.addLayout(self.modifyProductThumbSwitch_layout)
|
|
setting_layout.addLayout(self.modifyProductDetailSwitch_layout)
|
|
setting_layout.addLayout(self.modifyImageTranslationSwitch_layout)
|
|
setting_layout.addLayout(self.uploadToMarketSwitch_layout)
|
|
setting_layout.addLayout(self.alwaysOnTopSwitch_layout)
|
|
setting_layout.addLayout(self.shutdownSwitch_layout)
|
|
|
|
self.setLayout(layout)
|
|
self.setWindowTitle('AutoPercenty')
|
|
|
|
def create_label_and_switch(self, label_text, target_switch):
|
|
layout = QtWidgets.QHBoxLayout()
|
|
label = QtWidgets.QLabel(label_text)
|
|
|
|
layout.addWidget(label)
|
|
layout.addWidget(target_switch)
|
|
|
|
return layout
|
|
|
|
def center(self):
|
|
# 화면 중앙에 위치시키기 위한 계산
|
|
qr = self.frameGeometry() # 위젯의 직사각형 정보를 얻습니다.
|
|
cp = QtWidgets.QDesktopWidget().availableGeometry().center() # 사용 가능한 화면의 중앙 위치를 얻습니다.
|
|
qr.moveCenter(cp) # 직사각형의 중심을 화면의 중심 위치로 이동시킵니다.
|
|
self.move(qr.topLeft()) # 위젯의 시작점을 직사각형의 시작점으로 이동시켜 화면 중앙에 위치시킵니다.
|
|
|
|
|
|
def toggleAlwaysOnTop(self, checked):
|
|
if checked:
|
|
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
|
|
else:
|
|
self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def shutdownAfterComplete(self, checked):
|
|
if checked:
|
|
self.whether_shutdownAfterComplete = True
|
|
else:
|
|
self.whether_shutdownAfterComplete = False
|
|
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyProductName(self, checked):
|
|
if checked:
|
|
self.whether_modifyProductName = True
|
|
else:
|
|
self.whether_modifyProductName = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyProductOptions(self, checked):
|
|
if checked:
|
|
self.whether_modifyProductOptions = True
|
|
else:
|
|
self.whether_modifyProductOptions = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyProductTag(self, checked):
|
|
if checked:
|
|
self.whether_modifyProductTag = True
|
|
else:
|
|
self.whether_modifyProductTag = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyProductPrice(self, checked):
|
|
if checked:
|
|
self.whether_modifyProductPrice = True
|
|
else:
|
|
self.whether_modifyProductPrice = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyProductThumb(self, checked):
|
|
if checked:
|
|
self.whether_modifyProductThumb = True
|
|
else:
|
|
self.whether_modifyProductThumb = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyProductDetail(self, checked):
|
|
if checked:
|
|
self.whether_modifyProductDetail = True
|
|
else:
|
|
self.whether_modifyProductDetail = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
def modifyImageTranslation(self, checked):
|
|
if checked:
|
|
self.whether_modifyImageTanslation = True
|
|
else:
|
|
self.whether_modifyImageTanslation = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
|
|
def uploadToMarket(self, checked):
|
|
if checked:
|
|
self.whether_uploadToMarket = True
|
|
else:
|
|
self.whether_uploadToMarket = False
|
|
self.show() # 변경된 윈도우 플래그를 적용하기 위해 위젯을 다시 보여줘야 함
|
|
|
|
|
|
def togglePasswordVisibility(self):
|
|
if self.showPasswordCheckBox.isChecked():
|
|
self.passwordInput.setEchoMode(QtWidgets.QLineEdit.Normal)
|
|
self.per_passwordInput.setEchoMode(QtWidgets.QLineEdit.Normal)
|
|
self.per_em_passwordInput.setEchoMode(QtWidgets.QLineEdit.Normal)
|
|
else:
|
|
self.passwordInput.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
self.per_passwordInput.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
self.per_em_passwordInput.setEchoMode(QtWidgets.QLineEdit.Password)
|
|
|
|
def focusToPassword(self):
|
|
self.passwordInput.setFocus()
|
|
|
|
|
|
def toggleMode(self, checked):
|
|
if checked:
|
|
self.changeModeButton.setText("직원용모드")
|
|
self.per_em_emailInput.setVisible(True)
|
|
self.per_em_passwordInput.setVisible(True)
|
|
self.per_passwordInput.setVisible(False)
|
|
self.per_mode = False # False일 경우 관리자
|
|
else:
|
|
self.changeModeButton.setText("관리자용모드")
|
|
self.per_em_emailInput.setVisible(False)
|
|
self.per_em_passwordInput.setVisible(False)
|
|
self.per_passwordInput.setVisible(True)
|
|
self.per_mode = True # True일 경우 직원용
|
|
|
|
# def checkToggleButtonState(self):
|
|
# if self.changeModeButton.isChecked():
|
|
# logger.debug("직원용모드 활성화")
|
|
# else:
|
|
# logger.debug("관리자용모드 활성화")
|
|
|
|
def saveSettings(self, email, password):
|
|
settings = QSettings("리앤수", "퍼센티자동화")
|
|
settings.setValue("email", self.emailInput.text())
|
|
settings.setValue("password", self.passwordInput.text())
|
|
settings.setValue("per_email", self.per_email)
|
|
settings.setValue("per_password", self.per_password)
|
|
settings.setValue("per_em_email", self.per_em_email)
|
|
settings.setValue("per_em_password", self.per_em_password)
|
|
settings.setValue("per_mode", self.per_mode)
|
|
settings.setValue("set_num_modify", self.set_num_modify)
|
|
|
|
|
|
def loadSettings(self):
|
|
settings = QSettings("리앤수", "퍼센티자동화")
|
|
self.emailInput.setText(settings.value("email", ""))
|
|
self.passwordInput.setText(settings.value("password", ""))
|
|
self.per_emailInput.setText(settings.value("per_email", ""))
|
|
self.per_passwordInput.setText(settings.value("per_password", ""))
|
|
self.per_em_emailInput.setText(settings.value("per_em_email", ""))
|
|
self.per_em_passwordInput.setText(settings.value("per_em_password", ""))
|
|
self.set_num_modifyInput.setText(settings.value("set_num_modify", "0"))
|
|
|
|
toggle_state = settings.value("per_mode", "false").lower() in ('true', '1', 'yes')
|
|
self.toggleMode(toggle_state)
|
|
|
|
def login(self):
|
|
email = self.emailInput.text()
|
|
password = self.passwordInput.text()
|
|
|
|
self.per_email = self.per_emailInput.text()
|
|
self.per_password = self.per_passwordInput.text()
|
|
self.per_em_email = self.per_em_emailInput.text()
|
|
self.per_em_password = self.per_em_passwordInput.text()
|
|
self.set_num_modify = self.set_num_modifyInput.text()
|
|
|
|
|
|
# MongoDB에서 사용자 문서 조회
|
|
user_doc = self.login_db.users.find_one({"email": email})
|
|
|
|
if user_doc and check_password_hash(user_doc['password'], password):
|
|
# 비밀번호 검증 성공
|
|
self.email = email # 여기에서 사용자 이메일을 self.email 속성에 저장
|
|
|
|
# 마지막 로그인 시간, 총 작업량, 주별 및 월별 성과 조회
|
|
last_login = user_doc.get('lastLoginTime', '기록 없음')
|
|
total_workload = user_doc.get('totalWorkload', 0)
|
|
weekly_performance = user_doc.get('weeklyPerformance', {})
|
|
monthly_performance = user_doc.get('monthlyPerformance', {})
|
|
# performance_msg = f"\n마지막 로그인 시간: {last_login}\n마지막 작업량: {total_workload}\n주간성과: {weekly_performance}\n월간성과: {monthly_performance}"
|
|
performance_msg = f"\n마지막 로그인 시간: {last_login}"
|
|
|
|
#QtWidgets.QMessageBox.information(self, "로그인 성공", performance_msg)
|
|
|
|
if user_doc['userType'] in ['slave', 'manager']:
|
|
self.master_email = user_doc.get('master', None)
|
|
logger.debug(f"설정된 마스터 이메일 : {self.master_email}")
|
|
|
|
QtWidgets.QMessageBox.information(self, "로그인 성공", f"{self.master_email} 데이터베이스를 사용합니다.\n{performance_msg}")
|
|
else:
|
|
QtWidgets.QMessageBox.information(self, "로그인 성공", f"{email} 데이터베이스를 사용합니다.\n{performance_msg}")
|
|
|
|
self.saveSettings(email, password) # 로그인 성공 시 설정 저장
|
|
|
|
now = datetime.now()
|
|
|
|
self.login_db.users.update_one(
|
|
{"email": email},
|
|
{"$set": {"lastLoginTime": now.strftime('%Y-%m-%d %H:%M:%S')}}
|
|
)
|
|
|
|
self.on_login_success()
|
|
else:
|
|
# 로그인 실패
|
|
QtWidgets.QMessageBox.warning(self, "로그인 실패", "이메일 또는 비밀번호가 잘못되었습니다.")
|
|
|
|
def on_login_success(self):
|
|
# MongoDB에서 사용자 문서 조회
|
|
user_doc = self.login_db.users.find_one({"email": self.email})
|
|
if user_doc['userType'] == 'master':
|
|
# 마스터 사용자 정보 표시
|
|
userInfo = f"등급: {user_doc['userGrade']}, 플랜 종료일: {user_doc['planEndDate']}"
|
|
# 종속된 사용자 정보 조회 및 표시
|
|
dependent_users = self.login_db.users.find({"master": user_doc['email']})
|
|
logger.debug(dependent_users)
|
|
#dependent_users = self.login_db.users.find({"master": self.email}) # 수정된 부분: user_doc['email'] 대신 self.email 사용
|
|
for user in dependent_users:
|
|
last_login = user.get('lastLoginTime', '로그인 기록 없음')
|
|
total_workload = user.get('totalWorkload', 0)
|
|
userInfo += f"\n종속 사용자: {user['email']}, 마지막 로그인: {last_login}, 총 작업량: {total_workload}"
|
|
elif user_doc['userType'] in ['slave', 'manager']:
|
|
userInfo = "해당 정보는 마스터 사용자만 볼 수 있습니다."
|
|
|
|
logger.debug(f"on_login_succes의 마스터 이메일 : {self.master_email}")
|
|
|
|
self.result = True
|
|
logger.debug(f"login_widget의 self.result : {self.result}")
|
|
|
|
# 로그인 시간 업데이트
|
|
now = datetime.now()
|
|
self.login_db.users.update_one(
|
|
{"email": self.email},
|
|
{"$set": {"lastLoginTime": now.strftime('%Y-%m-%d %H:%M:%S')}}
|
|
)
|
|
logger.debug(f"사용자 {self.email}의 로그인 시간이 기록되었습니다.")
|
|
|
|
self.close() # 로그인 창 닫기
|
|
# sys.exit()
|
|
# self.close() # 로그인 창 닫기
|
|
|
|
def find_master_username(self, slave_username):
|
|
# 실제 애플리케이션에서는 여기서 MongoDB를 조회하여 master 사용자를 찾아야 합니다.
|
|
# 이 예시에서는 단순화를 위해 'master' 문자열을 반환합니다.
|
|
return self.master_email
|
|
|
|
def login_user(self, email, password):
|
|
# 로그인 검증 로직 (생략)
|
|
now = datetime.now()
|
|
self.login_db.users.update_one(
|
|
{"email": email},
|
|
{"$set": {"lastLoginTime": now.strftime('%Y-%m-%d %H:%M:%S')}}
|
|
)
|
|
# 로그인 성공 메시지와 마지막 로그아웃 시간 표시 (구현 필요)
|
|
|
|
def logout(self, email):
|
|
logger.debug("로그아웃 프로세스 시작")
|
|
now = datetime.now()
|
|
# 로그아웃 시간 업데이트
|
|
self.login_db.users.update_one(
|
|
{"email": email},
|
|
{"$set": {"lastLogoutTime": now.strftime('%Y-%m-%d %H:%M:%S')}}
|
|
)
|
|
logger.debug(f"사용자 {email}의 로그아웃 시간이 기록되었습니다.")
|
|
# 변경된 문서 다시 조회
|
|
user_doc = self.login_db.users.find_one({"email": email})
|
|
|
|
# 성과 메시지 생성
|
|
performance_msg = self.create_performance_message(user_doc)
|
|
|
|
# 로그아웃 메시지 박스 표시 및 5초 후 자동 닫기
|
|
msgBox = QtWidgets.QMessageBox(self)
|
|
msgBox.setWindowTitle("로그아웃")
|
|
msgBox.setText("성공적으로 로그아웃되었습니다.\n" + performance_msg)
|
|
msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
|
|
msgBox.buttonClicked.connect(msgBox.close)
|
|
|
|
QTimer = QtCore.QTimer(self)
|
|
QTimer.singleShot(3000, msgBox.close) # 5초 후 자동 닫기
|
|
msgBox.exec_()
|
|
|
|
|
|
def show_user_performance(self, email):
|
|
user_doc = self.login_db.users.find_one({"email": email}, {"totalWorkload": 1, "weeklyPerformance": 1, "monthlyPerformance": 1})
|
|
if user_doc:
|
|
logger.debug(f"총 작업량: {user_doc.get('totalWorkload', 0)}")
|
|
logger.debug("주별 성과:")
|
|
for week, workload in user_doc.get("weeklyPerformance", {}).items():
|
|
logger.debug(f"{week}: {workload}")
|
|
logger.debug("월별 성과:")
|
|
for month, workload in user_doc.get("monthlyPerformance", {}).items():
|
|
logger.debug(f"{month}: {workload}")
|
|
|
|
|
|
def create_performance_message(self, user_doc):
|
|
# 마지막 로그인 시간, 총 작업량, 주별 및 월별 성과 조회
|
|
last_login = user_doc.get('lastLoginTime', '기록 없음')
|
|
total_workload = user_doc.get('totalWorkload', 0)
|
|
weekly_performance = user_doc.get('weeklyPerformance', {})
|
|
monthly_performance = user_doc.get('monthlyPerformance', {})
|
|
|
|
performance_msg = f"마지막 로그인 시간: {last_login}\n총 작업량: {total_workload}\n"
|
|
|
|
for week, workload in weekly_performance.items():
|
|
performance_msg += f"주별 성과 ({week}): {workload}\n"
|
|
for month, workload in monthly_performance.items():
|
|
performance_msg += f"월별 성과 ({month}): {workload}\n"
|
|
|
|
return performance_msg
|
|
|
|
|
|
def showSignUpWindow(self):
|
|
self.signUpWidget = SignUpWidget()
|
|
self.signUpWidget.show()
|
|
|
|
|
|
def check_for_updates(self, db, CURRENT_VERSION):
|
|
# 최신 버전 정보 조회
|
|
app_versions_collection = db['app_versions']
|
|
|
|
version_info = app_versions_collection.find_one({"_id": "app_version_info"})
|
|
if version_info and version_info["update_required"]:
|
|
latest_version = version_info["latest_version"]
|
|
update_url = version_info["update_url"]
|
|
|
|
if CURRENT_VERSION < latest_version:
|
|
print(f"새로운 버전이 있습니다: {latest_version}")
|
|
print(f"업데이트를 위해 여기를 방문하세요: {update_url}")
|
|
# 업데이트가 필요한 경우 사용자에게 알리고, 업데이트 페이지로 리다이렉트 등의 조치를 취합니다.
|
|
else:
|
|
print("최신 버전을 사용 중입니다.")
|
|
else:
|
|
print("버전 정보를 조회할 수 없습니다.") |