def check_authentication(self): hospital.execute("select User_Code from user where user.User_Code=%s and user.user_password=%s", (self.usercode, self.password)) user = hospital.fetchone() if user: hospital.execute("select Role_Name from user natural join user_role where user_Code = %s", (self.usercode,)) role = hospital.fetchone()[0] if role: if role == "admin": # go to admin page if role == "patient": # go to patient page elif role == "doctor": # go to doctor page elif role == "nurse": # go to nurse page elif role == "receptionist": # go to receptionist page elif role == "accountant": # go to accountant page elif role == "pharmacist": # go to pharmacist page elif role == "Lab_Staff": #go to lab staff page else: print("You are not authorized yet wait for Admin to activate your account!!!") else: print("Authentication failed!\n Wrong username or password!")
def send_data_to_database(self, change, string): print("sending data forget") email_text_edit = change.main_window.findChild(QLineEdit, "ForgetPageLineEdit") items = change.main_window.findChildren(QLineEdit) flag = True for item in items: if string in item.objectName(): if item.text() == "" and "Field" not in item.placeholderText(): text = item.placeholderText() item.setPlaceholderText("Fill Field: " + text) item.setStyleSheet("QLineEdit{ " "border:none;" "border-radius:5;" "background-color:#af2b44;}") flag = False hospital.execute( "select User_Code,user_password from user where `E-Mail`=%s", (email_text_edit.text(), )) result = hospital.fetchone() if not result: print("there is no email address registered as you requested!!") return user_code = result[0] user_password = result[1] if flag: self.email(email_text_edit.text(), user_code, user_password)
def send_data_to_database(self, change, string): print("sending data registeration") username_text_edit = change.main_window.findChild( QLineEdit, "RegisterPageUsernameLineEdit") password_text_edit = change.main_window.findChild( QLineEdit, "RegisterPagePasswordLineEdit") password_confirm_text_edit = change.main_window.findChild( QLineEdit, "RegisterPageConfirmPasswordLineEdit") email_text_edit = change.main_window.findChild( QLineEdit, "RegisterPageEmailLineEdit") phone_text_edit = change.main_window.findChild( QLineEdit, "RegisterPagePhoneNumberLineEdit") items = change.main_window.findChildren(QLineEdit) combo = change.main_window.findChild(QComboBox, "RegisterPageComboBox") flag = True for item in items: if string in item.objectName(): if item.text() == "" and "Field" not in item.placeholderText(): text = item.placeholderText() item.setPlaceholderText("Fill Field: " + text) item.setStyleSheet("QLineEdit{ " "border:none;" "color:white;" "border-radius:5;" "background-color:#af2b44;}") flag = False if combo.currentText() == "": print("you have to choose a role") return if password_confirm_text_edit.text() != password_text_edit.text(): print("confirm password does not match") return if flag: try: query = "insert into user(Username,user_password,Phone_Number,`E-Mail`,isVerified) values(%s,%s,%s,%s,0)" val = (username_text_edit.text(), password_text_edit.text(), phone_text_edit.text(), email_text_edit.text()) hospital.execute(query, val) except Exception as e: print(e) return mydb.commit() self.email(username_text_edit.text(), email_text_edit.text()) print("you are registered! please wait for verification!!!!") hospital.execute("select role_ID from role where Role_Name=%s", (combo.currentText(), )) role_id = hospital.fetchone()[0] hospital.execute( " insert into user_role(user_Code, role_ID) values(last_insert_id(),%s)", (role_id, )) mydb.commit() self.registered = True
def send_nurse_report_logic_page(self, change, usercode): submit_button = change.main_window.findChild( QPushButton, "NursePageSubmitReportButton") submit_button.clicked.connect(lambda: self.send_data_to_database( change.main_window, "NursePage")) nurse_username = change.main_window.findChild(QLabel, "NursePageUsername") print("username is:", usercode) hospital.execute("select Username from user where User_Code = %s", (usercode, )) username = hospital.fetchone()[0] nurse_username.setText(username) print(nurse_username.text()) records_button = change.main_window.findChild( QPushButton, "NursePageResportsRecordButton") records_button.clicked.connect(lambda: change.change_page(change, 5))
def email(self): message = """Subject: Your username for login Hi {username}, your username for login is {user_code}""" name = self.username query = "select User_Code form user where 'E-Mail'=%s" hospital.execute(query, (self.email,)) user_code = hospital.fetchone()[0] from_address = "*****@*****.**" email = self.email try: server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(from_address, "11kahani") server.sendmail(from_address, email, message.format(name=name, grade=user_code)) server.close() print('Email sent!') except: print("Something went wrong :(")
def email(self, username, email_address): message = """Subject: Your username for login Hi {username}, your username for login is {user_code}""" name = username print(name) query = "select last_insert_id()" hospital.execute(query) user_code = hospital.fetchone()[0] email = email_address try: from_address = "*****@*****.**" server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(from_address, "11kahani") server.sendmail(from_address, email, message.format(username=name, user_code=user_code)) server.close() print('Email sent!') except: print("something went wrong!!")