def view_info(user, school): global header global result header = ("Forename", "Surname", "Age", "Class") widths = [len(cell) for cell in header] result = "blank" if school is "Student": view = ("SELECT Forename,Surname,Age,Class FROM Students WHERE username = ?") cursor.execute(view, [(user)]) student_check = cursor.fetchone() for i, cell in enumerate(student_check): widths[i] = max(len(str(cell)), widths[i]) formatted_row = ' '.join('{:%d}' % width for width in widths) header = formatted_row.format(*header) result = formatted_row.format(*student_check) return "S" elif school is "Teacher": view = ("SELECT Forename,Surname,Age,Class FROM Teachers WHERE username = ?") cursor.execute(view, [(user)]) teacher_check = cursor.fetchone() for i, cell in enumerate(teacher_check): widths[i] = max(len(str(cell)), widths[i]) formatted_row = ' '.join('{:%d}' % width for width in widths) header = formatted_row.format(*header) result = formatted_row.format(*teacher_check) return "T"
def student_email( email ): # checks the email the user entered against the student database find_student = ("SELECT Students.email FROM Students WHERE email = ?") # sql statement checks based on email variable condition cursor.execute(find_student, [(email)]) # execution of sql statement result = cursor.fetchone() # gets one value if result is not None: # checks based on condition that there is values to check db_email = result # sets the value db_email based on result if email == db_email: # checks user input against database value return True # if condition is met it returns true else: return False # if condition not met it returns false
def student_check(username, password): # Used for the login function this checks against the username and password the user enters in students table find_user = ("SELECT username,password FROM Students WHERE username = ?") # sql statement for getting the username and password cursor.execute(find_user, [(username)]) #executes the above sql code checking = cursor.fetchone() # fetchs one of the values if checking is not None: # if there are values in check then it goes through this process db_user, db_password = checking # gets username and password stored in the database if (username == db_user) and (bcrypt.checkpw(password.encode("utf8"), db_password) is True): #checks the database username and password against the username and password stored return True # if condition met return true else: return False # if condition not met return False
def get_surname( user_id ): # gets the user surname using the user id from the table Students sql_surname = """SELECT Surname FROM Students WHERE ID = ?""" cursor.execute(sql_surname, [(user_id)]) return cursor.fetchone()[0] # returns the surname of the user
def get_student(username): # uses a parameter username sql = "SELECT ID FROM Students WHERE username = ? " # sql for searching for the ID connected to the username cursor.execute(sql, [(username)]) # execution of search for ID return cursor.fetchone()[0] # returns the value of the id
def get_id_student(username): # function for getting the student id # sql that takes the username and returns ID sql = "SELECT ID FROM Students WHERE username = ?" cursor.execute(sql, [(username)]) # execution of the sql return cursor.fetchone()[0] # returns the integer value of ID
def get_id_student(username): sql = "SELECT ID FROM Students WHERE username = ?" cursor.execute(sql, [(username)]) return cursor.fetchone()[0]