-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac58bee
commit c7dcd51
Showing
2 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters