import sqlite3

from hacksport.problem import files_from_directory, PHPApp, ProtectedFile


class Problem(PHPApp):
    files = files_from_directory("webroot/") + [ProtectedFile("users.db")]
    php_root = "webroot/"
    num_workers = 5

    def setup(self):
        conn = sqlite3.connect("users.db")
        conn.cursor().execute("PRAGMA journal_mode = MEMORY")
        conn.commit()
        
        c = conn.cursor()
        c.execute("CREATE TABLE users (name text, password text, admin integer, question1 text, answer1 text, question2 text, answer2 text);")

        # This is static. However, there is no reason it couldn't be autogenerated!
        c.execute(
            """INSERT INTO users VALUES ('hubert423', 'nFTHEHhMM2RNacEp', 1, 'What is the name of your favorite pet?', 'Max', 'What is the name of your hometown?', 'Chapel Hill')"""
        )

        conn.commit()
        conn.close()
