def store_emails(self): email_count = 0 email_list = list() for lineEdit in self.lineEdits: email = lineEdit.text() if not email: continue else: if isValidEmail(email) or not self.email_exist(email): email_count += 1 email_list.append(email) else: QMessageBox.warning(self.label, "Invalid Information", "Email Exists or Invalid!", QMessageBox.Yes, QMessageBox.Yes) if email_count == 0: QMessageBox.warning(self.gridLayoutWidget , "Invalid Information", "Input at least one email", QMessageBox.Yes, QMessageBox.Yes) return connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("user_login.py login() Connected to MySQL server: ",db_Info) else: print("user_login.py login() Not Connected ") cursor = connection_object.cursor() sql = "delete from emails where Username = \'" + self.user_name + "\';" cursor.execute(sql) connection_object.commit() for e in email_list: sql = "insert into emails values (\'" + self.user_name + "\', \'" + e + "\');" cursor.execute(sql) connection_object.commit() if(connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") self.stored = True
def login(self): pwd = self.lineEdit_2.text() email = self.lineEdit.text() if not isValidEmail(email): QMessageBox.warning(self.label, "Invalid Information", "Invalid email!", QMessageBox.Yes, QMessageBox.Yes) return #TODO: SQL query to search for the user with email and password in the database query1 = "SELECT Username FROM emails WHERE Email = \'" + email + "\';" connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("user_login.py login() Connected to MySQL server: ", db_Info) else: print("user_login.py login() Not Connected ") cursor = connection_object.cursor() cursor.execute(query1) result = cursor.fetchall() ############################ if len(result) == 0: QMessageBox.warning(self.label, "Invalid Information", "Email Does Not Exist!", QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return user_name = result[0][0] query1 = "SELECT Password,UserType,Status FROM user WHERE Username = \'" + user_name + "\';" cursor.execute(query1) result = cursor.fetchall() password = result[0][0] user_type = result[0][1] status = result[0][2] exist = False if verify_password(password, pwd): print("wrong passwd") exist = True if status == "Declined": exist = False if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") ############################ function_screens = { "User": 7, "Administrator": 8, "Administrator_Visitor": 9, "Manager": 10, "Manager_Visitor": 11, "Staff": 12, "Staff_Visitor": 13, "Visitor": 14 } if exist: if user_type == "User": __main__.user_type = "User" elif self.isVisitor(user_name): if self.isManager(user_name): __main__.user_type = "Manager_Visitor" elif self.isStaff(user_name): __main__.user_type = "Staff_Visitor" elif self.isAdmin(user_name): __main__.user_type = "Administrator_Visitor" else: __main__.user_type = "Visitor" else: if self.isManager(user_name): __main__.user_type = "Manager" elif self.isStaff(user_name): __main__.user_type = "Staff" elif self.isAdmin(user_name): __main__.user_type = "Administrator" __main__.logged_user = user_name __main__.screen_number = function_screens[__main__.user_type] app.exit() else: QMessageBox.warning( self.label, "Invalid Information", "Invalid email or password or Declined Status! ", QMessageBox.Yes, QMessageBox.Yes)
def register(self): fname = self.firstNameLineEdit.text() lname = self.lastNameLineEdit.text() user_name = self.userNameLineEdit.text() pwd = self.passwordLineEdit.text() c_pwd = self.confirmedPasswordLineEdit.text() user_type = self.userTypeComboBox.currentText() phone = self.phoneLineEdit.text() address = self.addressLineEdit.text() city = self.city_input.text() state = self.state_input.currentText() zipcode = self.zipcode_input.text() #######################check user name#################### connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("register_user.py Connected to MySQL server: ", db_Info) else: print("register_user.py Not Connected ") cursor = connection_object.cursor() query1 = "select count(*) from user where Username = \'" + user_name + "\';" cursor.execute(query1) result = cursor.fetchall() if result[0][0] != 0: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "This user name is registerd", QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") ###################check empty or invalid################################# if ' ' in fname or len(fname) == 0: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "First Name can not be NULL. First Name can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return if ' ' in lname or len(lname) == 0: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "Last Name can not be NULL. Last Name can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return if ' ' in user_name or len(user_name) == 0: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "User Name can not be NULL. User Name can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return # TODO: check dupicated user name if ' ' in pwd or len(pwd) < 8: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "Password should be at least 8 characters. Password can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return if not pwd == c_pwd: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Password and Confirmed Password don't match", QMessageBox.Yes, QMessageBox.Yes) return if not isValidPhone(phone) or self.phoneExist(phone): QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "Invalid Phone Number or Phone Number Exists: %s" % (phone), QMessageBox.Yes, QMessageBox.Yes) return if not isValidZipcode(zipcode): QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Invalid Zipcode: %s" % (zipcode), QMessageBox.Yes, QMessageBox.Yes) return #################check emails####################################### connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("register_user.py Connected to MySQL server: ", db_Info) else: print("register_user.py Not Connected ") cursor = connection_object.cursor() emails = list() for le in self.lineEdits: email = le.text() if not email: continue query2 = "select count(*) from emails where Email = \'" + email + "\';" cursor.execute(query2) result = cursor.fetchall() if result[0][0] != 0: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "This email is registerd: %s" % (email), QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return if not isValidEmail(email): QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Invalid Email address: %s" % (email), QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return else: emails.append(email) print(emails) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") if len(emails) == 0: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Input at least one email", QMessageBox.Yes, QMessageBox.Yes) return ########################## store info to database########################## pwd = hash_password(pwd) query3 = "insert into user values (\'" + user_name + "\',\'" + pwd + "\'," + "\'Pending\'" + ",\'" + fname + "\',\'" + lname + "\',\'" + user_type + "\');" connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("register_user.py Connected to MySQL server: ", db_Info) else: print("register_user.py Not Connected ") cursor = connection_object.cursor() cursor.execute(query3) #connection_object.commit() print(query3) eid = str(uuid.uuid4().fields[-1])[:9] query5 = "insert into employee values (\'" + user_name + "\',\'" + eid + "\',\'" + phone + "\',\'" + address + "\',\'" + city + "\',\'" + state + "\',\'" + zipcode + "\');" cursor.execute(query5) #connection_object.commit() print(query5) query6 = "insert into visitor values (\'" + user_name + "\')" cursor.execute(query6) print(query6) if user_type == "Manager": query7 = "insert into manager values(\'" + user_name + "\',\'Manager\')" elif user_type == "Staff": query7 = "insert into staff values(\'" + user_name + "\',\'Staff\')" cursor.execute(query7) for email in emails: query4 = "insert into emails values ( \'" + user_name + "\',\'" + email + "\');" cursor.execute(query4) print(query4) connection_object.commit() if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed")
def register(self): fname = self.firstNameLineEdit.text() lname = self.lastNameLineEdit.text() user_name = self.usernameLineEdit.text() pwd = self.passwordLineEdit.text() c_pwd = self.confirmPasswordLineEdit.text() #######################check user name#################### connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("register_user.py Connected to MySQL server: ", db_Info) else: print("register_user.py Not Connected ") cursor = connection_object.cursor() query1 = "select count(*) from user where Username = \'" + user_name + "\';" cursor.execute(query1) result = cursor.fetchall() if result[0][0] != 0: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "This user name is registerd", QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") ###################check empty or invalid################################# if ' ' in fname or len(fname) == 0: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "First Name can not be NULL. First Name can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return if ' ' in lname or len(lname) == 0: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "Last Name can not be NULL. Last Name can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return if ' ' in user_name or len(user_name) == 0: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "User Name can not be NULL. User Name can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return # TODO: check dupicated user name if ' ' in pwd or len(pwd) < 8: QMessageBox.warning( self.gridLayoutWidget, "Invalid Information", "Password should be at least 8 characters. Password can not contain empty character", QMessageBox.Yes, QMessageBox.Yes) return if not pwd == c_pwd: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Password and Confirmed Password don't match", QMessageBox.Yes, QMessageBox.Yes) return #################check emails####################################### connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("register_user.py Connected to MySQL server: ", db_Info) else: print("register_user.py Not Connected ") cursor = connection_object.cursor() emails = list() for le in self.lineEdits: email = le.text() if not email: continue query2 = "select count(*) from emails where Email = \'" + email + "\';" cursor.execute(query2) result = cursor.fetchall() if result[0][0] != 0: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "This email is registerd: %s" % (email), QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return if not isValidEmail(email): QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Invalid Email address: %s" % (email), QMessageBox.Yes, QMessageBox.Yes) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") return else: emails.append(email) print(emails) if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") if len(emails) == 0: QMessageBox.warning(self.gridLayoutWidget, "Invalid Information", "Input at least one email", QMessageBox.Yes, QMessageBox.Yes) return ########################## store info to database########################## pwd = hash_password(pwd) query3 = "insert into user values (\'" + user_name + "\',\'" + pwd + "\'," + "\'Pending\'" + ",\'" + fname + "\',\'" + lname + "\',\'User\');" connection_object = __main__.connection_pool.get_connection() if connection_object.is_connected(): db_Info = connection_object.get_server_info() print("register_user.py Connected to MySQL server: ", db_Info) else: print("register_user.py Not Connected ") cursor = connection_object.cursor() cursor.execute(query3) #connection_object.commit() print(query3) for email in emails: query4 = "insert into emails values ( \'" + user_name + "\',\'" + email + "\');" cursor.execute(query4) #connection_object.commit() print(query4) connection_object.commit() if (connection_object.is_connected()): cursor.close() connection_object.close() print("MySQL connection is closed") QMessageBox.information(self.label, "Operation Success", "Operation Success", QMessageBox.Yes)