Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ def register():
flash("Passwords do not match")
return render_template("auth.html", active_tab="register")

existing_user = db.execute("SELECT * FROM users WHERE username = ?", username)
existing_user = db.execute("SELECT * FROM users WHERE username = :username", {"username": username})
if existing_user:
flash("Username already exists")
return render_template("auth.html", active_tab="register")

hashed_password = generate_password_hash(password)
db.execute("INSERT INTO users (username, hash) VALUES (?, ?)", username, hashed_password)
db.execute("INSERT INTO users (username, hash) VALUES (:username, :hash)", {"username": username, "hash": hashed_password})

flash("Registered successfully!")
return redirect("/login")
Expand All @@ -101,7 +101,7 @@ def login():
flash("Must provide password")
return render_template("auth.html", active_tab="login")

rows = db.execute("SELECT * FROM users WHERE username = ?", username)
rows = db.execute("SELECT * FROM users WHERE username = %s", (username,))

if len(rows) != 1 or not check_password_hash(rows[0]["hash"], password):
flash("Invalid username and/or password")
Expand Down Expand Up @@ -134,13 +134,13 @@ def reset_password():
return render_template("reset_password.html")

# Verify username exists
rows = db.execute("SELECT * FROM users WHERE username = ?", username)
rows = db.execute("SELECT * FROM users WHERE username = :username", {"username": username})
if len(rows) != 1:
flash("Username not found")
return render_template("reset_password.html")

hashed_password = generate_password_hash(new_password)
db.execute("UPDATE users SET hash = ? WHERE username = ?", hashed_password, username)
db.execute("UPDATE users SET hash = :hash WHERE username = :username", {"hash": hashed_password, "username": username})

flash("Password reset successfully! You can now log in.")
return redirect("/login")
Expand Down Expand Up @@ -171,7 +171,7 @@ def planner():
if not course_name:
flash("Course name cannot be empty", "danger")
return redirect("/planner")
db.execute("INSERT INTO courses (user_id, name) VALUES (?, ?)", user_id, course_name)
db.execute("INSERT INTO courses (user_id, name) VALUES (:user_id, :name)", {"user_id": user_id, "name": course_name})
flash("Course added successfully!", "success")
return redirect("/planner")

Expand Down