Skip to content

Commit

Permalink
#2 로그인 성공 후 메뉴로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesun147 committed May 30, 2023
1 parent ac58bee commit c7dcd51
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
79 changes: 79 additions & 0 deletions login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import mysql.connector as mc
from PyQt5.QtWidgets import *
import sys
from menu import MainMenu

# MySQL 연결 설정
def connect_to_mysql():
mydb = mc.connect(
host="34.22.65.53",
user="root",
password="cms",
database="cms"
)
return mydb

class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.title = "Login"
self.initUI()
self.main_menu = None # MainMenu 인스턴스

def initUI(self):
self.setWindowTitle(self.title)

self.label_email = QLabel("Email:", self)
self.lineEdit_email = QLineEdit(self)

self.label_password = QLabel("Password:", self)
self.lineEdit_password = QLineEdit(self)
self.lineEdit_password.setEchoMode(QLineEdit.Password)

self.button_login = QPushButton("Login", self)
self.button_login.clicked.connect(self.login)

layout = QVBoxLayout()
layout.addWidget(self.label_email)
layout.addWidget(self.lineEdit_email)
layout.addWidget(self.label_password)
layout.addWidget(self.lineEdit_password)
layout.addWidget(self.button_login)

self.setLayout(layout)

def login(self):
email = self.lineEdit_email.text()
password = self.lineEdit_password.text()

# MySQL 연결
mydb = connect_to_mysql()
mycursor = mydb.cursor()

# id와 password로 인증 확인
query = "SELECT id FROM teacher WHERE id = %s AND password = %s"
values = (email, password)
mycursor.execute(query, values)
result = mycursor.fetchone()

if result is not None:
self.hide()
self.main_menu = MainMenu() # MainMenu 인스턴스 생성
self.main_menu.show()
else:
QMessageBox.warning(self, "Login Failed", "Incorrect email or password")

# 연결 종료
mycursor.close()
mydb.close()

def closeEvent(self, event):
if self.main_menu is not None:
self.main_menu.show() # 메인 메뉴 창 보여주기
event.accept()

if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = LoginWindow()
mainWindow.show()
sys.exit(app.exec_())
12 changes: 7 additions & 5 deletions menu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel
from register import Register
from attendance import Attendance
import sys

class MainMenu(QWidget):
def __init__(self):
Expand Down Expand Up @@ -33,7 +34,8 @@ def open_attendance(self):
self.attendance = Attendance(self)
self.attendance.show()

app = QApplication([])
ex = MainMenu()
ex.show()
app.exec_()
if __name__ == "__main__":
app = QApplication([])
ex = MainMenu()
ex.show()
app.exec_()

0 comments on commit c7dcd51

Please sign in to comment.