def forgot_password( email, new_pass, confirm_pass): # Used to change the user password if forgotten if password_check( new_pass, confirm_pass ) is True: # validation for password from remake_register password_store = bcrypt.hashpw(new_pass.encode("utf8"), bcrypt.gensalt()) # changes the password into a hashed value using bcrypt if (student_email(email) is not False and teacher_email(email) is False): # Checks if the email is in the student table and not in the teacher table update_student = ("UPDATE Students SET password=? WHERE email=?") # sql for changing the student password cursor.execute(update_student, [(password_store), (email)]) # executes the sql statement with password_store variable that has the specific email db.commit() # saves changes made return True # refers back to the tkinter page elif (student_email(email) is False and teacher_email(email) is not False): # email must be in teacher table and not student table update_teacher = ("UPDATE Teachers SET password=? WHERE email=?") # sql statement for changing the teacher password cursor.execute(update_teacher, [(password_store), (email)]) # executes the sql statement with password_store variable on the condition of the user that has the email db.commit() # save changes made return True # refers back to the tkinter page else: messagebox.showerror( "Email", "Email doesn't exist either message support or register as you haven't made an account" ) # this is error message shown if student_check and teacher check fails else: pass # no error message is needed here as password_check has its own error messages
def end_loop(loop, user, correct, incorrect, score, level, total): if total == 0: # no questions attempted return False else: store_id = get_student(user) # gets the user id using get_student total = len(question_store) # gets the len of question store for total questions attempted if loop is "Pure": # if loop is pure sql = """INSERT INTO pure_results (user_id,level, score, Correct, Incorrect,total_questions, time_stamp) VALUES (?, ?, ?, ?, ?, ?,?) """ # sql for inserting a record into pure_results table cursor.execute( sql, [(store_id), (level), (score), (correct), (incorrect), (total), (current_date)]) # executes the statment with python variales db.commit() # saves changes made to database file question_store.clear() # removes all the values in question_store return True elif loop is "Applied": # if loop is applied sql = """INSERT INTO applied_results (user_id,level, score, Correct, Incorrect,total_questions, time_stamp) VALUES (?, ?, ?, ?, ?, ?,?) """ # sql for inserting a record into applied_results table cursor.execute( sql, [(store_id), (level), (score), (correct), (incorrect), (total), (current_date)]) # executes the statment with python variales db.commit() # saves changes made to database file question_store.clear() # removes all the values in question_store return True
def register2(username, password, confirm_password, email, var1): # checks whether a existing username with the username enter exists if username_check(username): # ensures the password passes all the vaildations if password_check(password, confirm_password): password_store = bcrypt.hashpw(password.encode("utf8"), bcrypt.gensalt()) if email_check(email): # ensures the email passes the vaildation if var1 == 1: # inserts one whole record into student table insert_student = ( "INSERT INTO Students(Forename,Surname,Age,Class,Gender,Username,Password,Email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ) cursor.execute(insert_student, [(shared_data["firstname"]), (shared_data["surname"]), (shared_data["age"]), (shared_data["Class"]), (shared_data["gender"]), (username), (password_store), (email)]) send_email(email, username) elif var1 == 2: # inserts one whole record into the teacher table insert_teacher = ( "INSERT INTO Teachers(Forename,Surname,Age,Class,Gender,Username,Password,Email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ) cursor.execute(insert_teacher, [(shared_data["firstname"]), (shared_data["surname"]), (shared_data["age"]), (shared_data["Class"]), (shared_data["gender"]), (username), (password_store), (email)]) send_email(email, username) db.commit() # saves the changes to the database file return True else: return False else: return False else: return False
def forgot_password( email, new_pass, confirm_pass): # Used to change the user password if forgotten if (student_email(email) is not False and teacher_email(email) is False): if password_check( new_pass, confirm_pass ) is True: # validation for password from remake_register password_store = bcrypt.hashpw( new_pass.encode("utf8"), bcrypt.gensalt()) # hashes the new password update_student = ("UPDATE Students SET password=? WHERE email=?") # updates the password based on the user email and it being a student cursor.execute( update_student, [(password_store), (email)]) # performs the update on the Student table db.commit() # saves changes made return True # refers back to the tkinter page elif (student_email(email) is False and teacher_email(email) is not False): if password_check( new_pass, confirm_pass ) is True: # validation for password from remake_register password_store = bcrypt.hashpw( new_pass.encode("utf8"), bcrypt.gensalt()) # hashes the new password update_student = ("UPDATE Teachers SET password=? WHERE email=?") # updates the password based on the user email and it being a teacher cursor.execute(update_student, [(password_store), (email)]) # performs the update on the Teacher table db.commit() # saves changes made return True # refers back to the tkinter page else: # if either condition is met then it returns an tkinter error message messagebox.showerror( "Email", "Email doesn't exist either message support or register as you haven't made an account" ) # this is error message
Username VARCHAR(30),Password VARCHAR(80), Email VARCHAR(30))""" ) create_teacher_table = ( """CREATE TABLE IF NOT EXISTS Teachers( ID INTEGER PRIMARY KEY, Forename VARCHAR(30) , Surname VARCHAR(30) , Age INTEGER , Class VARCHAR (3) , Gender VARCHAR (30), Username VARCHAR(30), Password VARCHAR(80), Email VARCHAR(30))""" ) # Sql statment to create the table where the user information will be stored cursor.execute(create_student_table) # executes the sql statement # Sql statment to create the table where the user information will be stored cursor.execute(create_teacher_table) # executes the sql statement db.commit() # saves changes made to the sql file def get_forename( user_id ): # gets the user forename using the user id from the table Students sql_forename = """SELECT Forename FROM Students WHERE ID = ?""" cursor.execute(sql_forename, [(user_id)]) return cursor.fetchone()[0] # returns the forename of the user 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)])
def make_question(question_text, type, level, answer): answer_string = str(answer) match = re.match("[\w,\s,.]*$", question_text) if match is not None and (len(question_text) >= 50): if type is 1: question_type = "Pure" if level is 1: if answer_string.isalnum() is True: question_level = "AS" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question,answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: if answer_string.isalnum() is True: question_level = "A2" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: messagebox.showerror("Level", "Level cannot be left blank") elif type is 2: question_type = "Applied" if level is 1: if answer_string.isalnum() is True: question_level = "AS" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: if answer_string.isalnum() is True: question_level = "A2" insert_question = ( """INSERT INTO maths_questions(test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) cursor.execute(insert_question, [(question_type), (question_level), (question_text), (str(answer))]) db.commit() return True else: messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: messagebox.showerror("Level", "Level cannot be left blank") else: messagebox.showerror("Type", "Type cannot be left blank") else: messagebox.showerror( "Question", "Question cannot be left blank and make a reasonable question")
from create_connection import cursor, cursor1, db current_date = dt.date.today().strftime("%Y-%m-%d") create_pure_table = """CREATE TABLE IF NOT EXISTS pure_results (maths_id INTEGER PRIMARY KEY, user_id INTEGER, level TEXT , score INTEGER , total_questions INTEGER, Correct INTEGER, Incorrect INTEGER, time_stamp DATE, FOREIGN KEY (user_id) REFERENCES Students(ID))""" create_applied_table = """CREATE TABLE IF NOT EXISTS applied_results (maths_id INTEGER PRIMARY KEY, user_id INTEGER, level TEXT , score INTEGER ,total_questions INTEGER, Correct INTEGER, Incorrect INTEGER, time_stamp DATE,FOREIGN KEY (user_id) REFERENCES Students(ID))""" cursor.execute(create_pure_table) cursor.execute(create_applied_table) create_question_table = """CREATE TABLE IF NOT EXISTS maths_questions(question_id INTEGER PRIMARY KEY, test_type TEXT,test_level TEXT, question TEXT, answer TEXT) """ cursor.execute(create_question_table) db.commit() question_store = [] questions = [] question_answers = [] def make_question(question_text, type, level, answer): answer_string = str(answer) match = re.match("[\w,\s,.]*$", question_text) if match is not None and (len(question_text) >= 50): if type is 1: question_type = "Pure" if level is 1: if answer_string.isalnum() is True: question_level = "AS"
def make_question(question_text, type, level, answer): # function for making questions # sql for inserting a question into maths questions insert_question = ("""INSERT INTO maths_questions (test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) answer_string = str(answer) # makes sure answer is in string form match = re.match( "[\w,\s,.]*$", question_text ) # ensures a space and alphanumeric characters in question text if match is not None and (len(question_text) >= 50): # question text has to be longer than 50 if type is 1: # when type is 1 question type is pure question_type = "Pure" if level is 1: # when level is 1 question type is AS if answer_string.isalnum( ) is True: # ensures question meets alphanumeric validation question_level = "AS" cursor.execute( insert_question, [ (question_type ), # executes inserts question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: # when level is 2 question type is A2 if answer_string.isalnum( ) is True: # ensures question meets alphanumeric validation question_level = "A2" cursor.execute( insert_question, [ (question_type ), # executes insert question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: # level can only be 1 or 2 if not then return error message messagebox.showerror("Level", "Level cannot be left blank") elif type is 2: # when type is 2 then question type is applied question_type = "Applied" if level is 1: # when level is 1 question type is AS if answer_string.isalnum( ) is True: # ensures question meets alphanumeric validation question_level = "AS" cursor.execute( insert_question, [ (question_type ), # executes insert question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") elif level is 2: if answer_string.isalnum( ) is True: # error message when answer doesn't meet alpha-numeric validation question_level = "A2" cursor.execute( insert_question, [ (question_type ), # executes insert question into db (question_level), (question_text), (str(answer)) ]) db.commit() # saves changes made and returns true return True else: # error message when answer doesn't meet alpha-numeric validation messagebox.showerror( "Answer", "Answer cannot be left blank and no spaces in answer") else: # when level is not 1 or 2 then return error message messagebox.showerror("Level", "Level cannot be left blank") else: # when type is not 1 or 2 then return error message messagebox.showerror("Type", "Type cannot be left blank") else: # when question doesn't meet the length requirement or regex expression return error message messagebox.showerror( "Question", "Question cannot be left blank and make a reasonable question")
current_date = dt.date.today().strftime("%Y-%m-%d") # current date # two database for storing pure and applied results create_pure_table = """CREATE TABLE IF NOT EXISTS pure_results (maths_id INTEGER PRIMARY KEY, user_id INTEGER, level TEXT , score INTEGER , total_questions INTEGER, Correct INTEGER, Incorrect INTEGER, time_stamp DATE, FOREIGN KEY (user_id) REFERENCES Students(ID))""" create_applied_table = """CREATE TABLE IF NOT EXISTS applied_results (maths_id INTEGER PRIMARY KEY, user_id INTEGER, level TEXT , score INTEGER ,total_questions INTEGER, Correct INTEGER, Incorrect INTEGER, time_stamp DATE,FOREIGN KEY (user_id) REFERENCES Students(ID))""" cursor.execute(create_pure_table) cursor.execute(create_applied_table) create_question_table = """CREATE TABLE IF NOT EXISTS maths_questions(question_id INTEGER PRIMARY KEY, test_type TEXT,test_level TEXT, question TEXT, answer TEXT) """ cursor.execute(create_question_table) db.commit() # saves changes made to db file question_store = [] # list for storing all the questions attempted def make_question(question_text, type, level, answer): # function for making questions # sql for inserting a question into maths questions insert_question = ("""INSERT INTO maths_questions (test_type, test_level, question, answer) VALUES (?, ?, ?, ?) """) answer_string = str(answer) # makes sure answer is in string form match = re.match( "[\w,\s,.]*$", question_text ) # ensures a space and alphanumeric characters in question text if match is not None and (len(question_text) >=