Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
query.py
venv/
.idea
.idea
database.db
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bookstore
# Bookstore
Bookstore is a web application by Alabamazon and is the final project for CNE 310 IT Project Management.

## Getting Started ##
Expand Down
Binary file modified database.db
Binary file not shown.
36 changes: 18 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def get_login_details():
no_of_items = 0
else:
logged_in = True
cur.execute("SELECT user_id, first_name FROM users WHERE email = '" + session['email'] + "'")
cur.execute("SELECT userId, firstName FROM users WHERE email = '" + session['email'] + "'")
user_id, first_name = cur.fetchone()
cur.execute("SELECT count(productId) FROM kart WHERE user_id = " + str(user_id))
cur.execute("SELECT count(productId) FROM kart WHERE userId = " + str(user_id))
no_of_items = cur.fetchone()[0]
conn.close()
return (logged_in, first_name, no_of_items)
Expand All @@ -34,15 +34,15 @@ def root():
with sqlite3.connect('database.db') as conn:
cur = conn.cursor()
# Show last product added
cur.execute('SELECT productId, name, price, description, image, stock FROM products ORDER BY productId DESC LIMIT 1 ')
cur.execute('SELECT productId, name, price, description, image, stock FROM products ORDER BY productId ')
# Show all items
#cur.execute('SELECT productId, name, price, description, image, stock FROM products LIMIT 1')
cur.execute('SELECT productId, name, price, description, image, stock FROM products')
item_data = cur.fetchall()
# Show an error instead of the categories
category_data = [(-1,"Error")]
#category_data = [(-1,"Error")]
# Show all categories
#cur.execute('SELECT categoryId, name FROM categories')
#category_data = cur.fetchall()
cur.execute('SELECT categoryId, name FROM categories')
category_data = cur.fetchall()
item_data = parse(item_data)
return render_template('home.html', itemData=item_data, loggedIn=logged_in, firstName=first_name, noOfItems=no_of_items, categoryData=category_data)

Expand Down Expand Up @@ -77,7 +77,7 @@ def addItem():
conn.commit()
msg="Added successfully"
except:
msg="Error occured"
msg="Error occurred"
conn.rollback()
conn.close()
print(msg)
Expand Down Expand Up @@ -113,7 +113,7 @@ def edit_profile():
logged_in, first_name, no_of_items = get_login_details()
with sqlite3.connect('database.db') as conn:
cur = conn.cursor()
cur.execute("SELECT userId, email, first_name, lastName, address1, address2, zipcode, city, state, country, phone FROM users WHERE email = '" + session['email'] + "'")
cur.execute("SELECT userId, email, firstName, lastName, address1, address2, zipcode, city, state, country, phone FROM users WHERE email = '" + session['email'] + "'")
profile_data = cur.fetchone()
conn.close()
return render_template("editProfile.html", profileData=profile_data, loggedIn=logged_in, firstName=first_name, noOfItems=no_of_items)
Expand Down Expand Up @@ -169,17 +169,17 @@ def update_profile():
msg = "Saved Successfully"
except:
con.rollback()
msg = "Error occured"
msg = "Error occurred"
con.close()
return redirect(url_for('edit_profile'))

@app.route("/loginForm")
def login_form():
# Uncomment to enable logging in and registration
#if 'email' in session:
if 'email' in session:
return redirect(url_for('root'))
#else:
# return render_template('login.html', error='')
else:
return render_template('login.html', error='')

@app.route("/login", methods = ['POST', 'GET'])
def login():
Expand Down Expand Up @@ -222,7 +222,7 @@ def add_to_cart():
msg = "Added successfully"
except:
conn.rollback()
msg = "Error occured"
msg = "Error occurred"
conn.close()
return redirect(url_for('root'))

Expand Down Expand Up @@ -251,15 +251,15 @@ def remove_from_cart():
product_id = int(request.args.get('productId'))
with sqlite3.connect('database.db') as conn:
cur = conn.cursor()
cur.execute("SELECT user_id FROM users WHERE email = '" + email + "'")
cur.execute("SELECT userId FROM users WHERE email = '" + email + "'")
user_id = cur.fetchone()[0]
try:
cur.execute("DELETE FROM kart WHERE user_id = " + str(user_id) + " AND productId = " + str(product_id))
cur.execute("DELETE FROM kart WHERE userId = " + str(user_id) + " AND productId = " + str(product_id))
conn.commit()
msg = "removed successfully"
except:
conn.rollback()
msg = "error occured"
msg = "error occurred"
conn.close()
return redirect(url_for('root'))

Expand Down Expand Up @@ -330,7 +330,7 @@ def register():
msg = "Registered Successfully"
except:
con.rollback()
msg = "Error occured"
msg = "Error occurred"
con.close()
return render_template("login.html", error=msg)

Expand Down