diff --git a/core/__pycache__/app.cpython-310.pyc b/core/__pycache__/app.cpython-310.pyc index 3936b63..95e8a46 100644 Binary files a/core/__pycache__/app.cpython-310.pyc and b/core/__pycache__/app.cpython-310.pyc differ diff --git a/core/__pycache__/database.cpython-310.pyc b/core/__pycache__/database.cpython-310.pyc new file mode 100644 index 0000000..c48c711 Binary files /dev/null and b/core/__pycache__/database.cpython-310.pyc differ diff --git a/core/app.py b/core/app.py index ddce27b..87bdfe3 100644 --- a/core/app.py +++ b/core/app.py @@ -4,13 +4,13 @@ from werkzeug.security import generate_password_hash, check_password_hash from functools import wraps from core.forms import SignupForm, LoginForm -from core.database import Database +from database.database import Database app = Flask(__name__, template_folder="../ui/templates/") app.config["SECRET_KEY"] = "" app.config["SESSION_PERMANENT"] = False app.config["SESSION_TYPE"] = "filesystem" -app.teardown_appcontext(Database.close_connection) + Session(app) @app.before_request @@ -58,7 +58,7 @@ def signup(): # Store in database and hash to avoid exposing sensitive information db = Database() - cursor = db.create_connection("../database/app.db") + cursor = db.create_connection() # Check if user already exists to avoid duplicates dup_email = cursor.execute("""SELECT * FROM users @@ -73,9 +73,9 @@ def signup(): elif password != password2: form.password.errors.append("Passwords must match.") else: - db.execute("""INSERT INTO users (username, password, email, num_followers, isPartenered, bio) + cursor.execute("""INSERT INTO users (username, password, email, num_followers, isPartenered, bio) VALUES (?, ?, ?, ?, ?, ?);""", (username, generate_password_hash(password), email, 0, 0, "This user does not have a Bio.")) - db.commit() + db.commit_data() return redirect(url_for("login")) @@ -94,7 +94,7 @@ def login(): # Compare with database db = Database() - cursor = db.create_connection("../database/app.db") + cursor = db.create_connection() # Check if user exists so only users who have signed up can login user_exists = cursor.execute("""SELECT * FROM users diff --git a/core/database.py b/core/database.py deleted file mode 100644 index d3ded0e..0000000 --- a/core/database.py +++ /dev/null @@ -1,15 +0,0 @@ -import sqlite3 - -class Database: - def __init__(self, db:str) -> None: - self._db = db - self._conn = None - - def create_connection(self) -> sqlite3.Cursor: - conn = sqlite3.connect(self._db) - self._conn = conn - cursor = conn.cursor() - return cursor - - def close_connection(self) -> None: - self._conn.close() \ No newline at end of file diff --git a/database/__pycache__/database.cpython-310.pyc b/database/__pycache__/database.cpython-310.pyc new file mode 100644 index 0000000..dcfaff9 Binary files /dev/null and b/database/__pycache__/database.cpython-310.pyc differ diff --git a/database/app.db b/database/app.db index e69de29..37d5a51 100644 Binary files a/database/app.db and b/database/app.db differ diff --git a/database/database.py b/database/database.py new file mode 100644 index 0000000..034a6ff --- /dev/null +++ b/database/database.py @@ -0,0 +1,22 @@ +import sqlite3 +import os + +class Database: + def __init__(self) -> None: + self._db = os.path.join(os.path.abspath(os.path.dirname(__file__)), "app.db") + + def create_connection(self) -> sqlite3.Cursor: + conn = sqlite3.connect(self._db) + conn.row_factory = sqlite3.Row + self._conn = conn + cursor = conn.cursor() + return cursor + + def commit_data(self): + try: + self._conn.commit() + except Exception as e: + print(e) + + def close_connection(self) -> None: + self._conn.close() \ No newline at end of file diff --git a/database/schema.sql b/database/schema.sql index 96f9ae8..8f8d7cd 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -5,10 +5,13 @@ CREATE TABLE users password VARCHAR(256) NOT NULL, email VARCHAR(64) NOT NULL, num_followers INTEGER NOT NULL, - isPartenered BOOLEAN NOT NULL DEFAULT 0 - bio TEXT, + isPartenered BOOLEAN NOT NULL DEFAULT 0, + bio TEXT ); +SELECT * FROM users; + + DROP TABLE IF EXISTS streams; CREATE TABLE streams ( diff --git a/flask_session/2029240f6d1128be89ddc32729463129 b/flask_session/2029240f6d1128be89ddc32729463129 new file mode 100644 index 0000000..8b04914 Binary files /dev/null and b/flask_session/2029240f6d1128be89ddc32729463129 differ diff --git a/flask_session/841e29f4900cf96cfb8ec55c0c598d2c b/flask_session/841e29f4900cf96cfb8ec55c0c598d2c new file mode 100644 index 0000000..bc2b512 Binary files /dev/null and b/flask_session/841e29f4900cf96cfb8ec55c0c598d2c differ diff --git a/ui/templates/index.html b/ui/templates/index.html index 51e5d33..7548bc5 100644 --- a/ui/templates/index.html +++ b/ui/templates/index.html @@ -1,20 +1,5 @@ {% extends "base.html" %} {% block main_content %} -