Example #1
0
def teacher_email(
        email
):  # checks the email the user entered against the teacher database
    find_teacher = ("SELECT Teachers.email FROM Teachers WHERE email = ?")
    # sql statement checks based on email variable condition
    cursor1.execute(find_teacher, [(email)])  # execution of sql statement
    checking = cursor1.fetchone()  # gets one value
    if checking is not None:  # checks based on condition that there is values to check
        db_email = checking  # 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
Example #2
0
def teacher_check(username, password):
    # Used for the login function this checks against the username and password the user enters in students table
    find_user1 = ("SELECT username,password FROM Teachers WHERE username = ?")
    # sql statement for getting the username and password
    cursor1.execute(find_user1, [(username)])  #executes the above sql code
    checking1 = cursor1.fetchone()  # fetchs one of the values
    if checking1 is not None:  # if there are values in check then it goes through this process
        db_user1, db_password1 = checking1  # gets username and password stored in the database
        if (username == db_user1) and (bcrypt.checkpw(password.encode("utf8"),
                                                      db_password1) 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
Example #3
0
def get_question(type, level):  # takes in params type and level
    query = "SELECT question,answer FROM maths_questions WHERE test_type = ? AND test_level = ?"  # sql query
    resp = pd.read_sql_query(query, db, params=[
        (type), (level)
    ])  # converts sql query into a pandas dataframe
    query1 = "SELECT COUNT(question_id) FROM maths_questions WHERE test_type=? AND test_level=?"
    # gets total amount of questions for the specific type and level (amount of records that met the requirements)
    cursor1.execute(query1, [(type),
                             (level)])  # calculates the value of above query
    total = cursor1.fetchone()[0]  # stores the value to a variable total
    rand_num = random_num(
        total)  # runs the function to generate a non-duplicate random number
    if rand_num is not "stop":  # continues until rand_num is stop
        return [resp["question"][rand_num],
                resp["Answer"][rand_num]]  # returns the question and answer
    else:
        return ["No more Questions", "END"]