Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
2
Indexable
Never
class LoginScreen(QDialog):
    def __init__(self, stacked_widget):
        super(LoginScreen, self).__init__()
        self.ui = Ui_login()
        self.ui.setupUi(self)
        self.stacked_widget = stacked_widget
        self.ui.btn_login.clicked.connect(self.loginfunction)

    def loginfunction(self):
        username = self.ui.input_username.text()
        password = self.ui.input_password.text()

        if len(username) == 0 or len(password) == 0:
            self.ui.error.setText('Input all fields.')
            return

        try:
            cur.execute('SELECT password FROM users WHERE username = %s', (username,))
            result_pass = cur.fetchone()
        except psycopg2.DatabaseError as e:
            self.ui.error.setText(f'Database error: {e}')
            return

        if result_pass and result_pass[0] == password:
            self.open_staff()
        else:
            self.ui.error.setText('Incorrect Username or Password.')

    def open_schedule(self):
        sched = ScheduleScreen(self.stacked_widget)
        self.stacked_widget.addWidget(sched)
        self.stacked_widget.setCurrentWidget(sched)

    def open_staff(self):
        staff = StaffScreen(self.stacked_widget)
        self.stacked_widget.addWidget(staff)
        self.stacked_widget.setCurrentWidget(staff)
Leave a Comment