def get_student_information(nuid):
        student_information_query = "SELECT * FROM students WHERE nuid = '%d'" % int(nuid)

        db_connection = DatabaseConnection.initiate_database_connection()
        cursor = db_connection.cursor()
        cursor.execute(student_information_query)

        student_information_result = cursor.fetchone()
        cursor.close()
        DatabaseConnection.exit_database_connection(db_connection)

        return student_information_result
    def add_student_information(nuid):
        first_name = input("Enter your first name: ")
        last_name = input("Enter your last name: ")
        level_study = input("Enter the level of study: ")
        department = input("Enter what department you are in: ")

        add_student_query = "INSERT INTO students " \
                            "(studentAccount_nuid, firstName, lastName, level, department)" \
                            "VALUES (%s, %s, %s, %s, %s)"

        data_student = (nuid, first_name, last_name, level_study, department)

        db_connection = DatabaseConnection.initiate_database_connection()
        cursor = db_connection.cursor()
        cursor.execute(add_student_query, data_student)
        cursor.close()
        DatabaseConnection.exit_database_connection(db_connection)
Exemple #3
0
    def get_student_account(username, password):

        db_connection = DatabaseConnection.initiate_database_connection()
        cursor = db_connection.cursor()

        student_account_sql = "SELECT *  FROM studentAccount " \
                              "WHERE username = %s "

        data_student_account = (username, )
        cursor.execute(student_account_sql, data_student_account)
        student_account_result = cursor.fetchone()

        cursor.close()
        DatabaseConnection.exit_database_connection(db_connection)

        if student_account_result and check_password_matches(
                student_account_result[2], password):
            return StudentAccount(int(student_account_result[0]), username,
                                  password)

        else:
            return
Exemple #4
0
    def add_student_account():

        username = input("Enter username: "******"Enter password: "******"INSERT INTO studentAccount (username, password)" \
                                    "VALUES (%s, %s)"

        hashed_password = hash_password(password)
        student_account_data = (username, hashed_password)

        db_connection = DatabaseConnection.initiate_database_connection()
        cursor = db_connection.cursor()
        cursor.execute(add_student_account_query, student_account_data)
        cursor.close()
        DatabaseConnection.exit_database_connection(db_connection)

        # adding student information after their account has been create
        student_account = StudentAccount.get_student_account(
            username, password)
        StudentInformation.add_student_information(student_account.nuid)
Exemple #5
0
from database_connection import DatabaseConnection

db_connection = DatabaseConnection.initiate_database_connection()

#cursor
cursor = db_connection.cursor()

#create a database
db = "CREATE DATABASE IF NOT EXISTS UNL"
cursor.execute(db)

#Drop the table when needed
# sql = "DROP TABLE UNL.userAccount"
# cursor.execute(sql)

#create table


studentInformationtable = "CREATE TABLE IF NOT EXISTS UNL.students (nuid INT PRIMARY KEY," \
        " firstName VARCHAR(255)," \
        " lastName VARCHAR(255)," \
        " level VARCHAR(255)," \
        " department VARCHAR(255))"

studentAccountTable = "CREATE TABLE IF NOT EXISTS UNL.studentAccount (nuid INT PRIMARY KEY," \
                   " username VARCHAR(255)," \
                   " password VARCHAR(255))"

cursor.execute(studentInformationtable)
cursor.execute(studentAccountTable)