Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c647d7e
Update README.md
lawcode1203 Jul 10, 2023
cab052d
p0
lawcode1203 Jul 10, 2023
8021b58
Working p1
lawcode1203 Jul 16, 2023
c18adb8
Update p1_Logan Woods.md
lawcode1203 Jul 16, 2023
39965d4
Update p1_Logan Woods.md
lawcode1203 Jul 17, 2023
829845b
Update p1_Logan Woods.md
lawcode1203 Jul 17, 2023
42a6d75
commit
lawcode1203 Jul 18, 2023
9c79fed
Commit
ratsmoothie Jul 18, 2023
7abe517
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
lawcode1203 Jul 18, 2023
06a398e
updated p1.md -Elijah
Erob494 Jul 18, 2023
9a575e2
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
lawcode1203 Jul 18, 2023
ea35c4c
Added lwoods14 info
lawcode1203 Jul 18, 2023
be07b95
UML diagrams added
lawcode1203 Jul 24, 2023
f1db8a7
Task 4
lawcode1203 Jul 25, 2023
7ae3eb0
inventory.puml
Erob494 Jul 25, 2023
329e1a4
Task 2
lawcode1203 Jul 25, 2023
729a38b
Location management
lawcode1203 Jul 25, 2023
b8e095f
core and authentication png and puml
Erob494 Jul 25, 2023
d6465a8
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
lawcode1203 Jul 25, 2023
a89f7d1
system puml
ratsmoothie Jul 25, 2023
fa88ea8
Added admin.html
lawcode1203 Jul 28, 2023
74b44be
Added Admin Control
lawcode1203 Jul 28, 2023
8c98384
Create products_manager.py
lawcode1203 Jul 30, 2023
2826958
added edited photos, ready to be uploaded to the website
ratsmoothie Jul 30, 2023
463fa3f
Modified Products Manager
lawcode1203 Jul 30, 2023
1f62e0c
Updated database to contain our products, and made the product cards …
ratsmoothie Jul 31, 2023
c5a6eaa
Added Wallet Manager
lawcode1203 Jul 31, 2023
f8d4e75
edited headings, added wallet button and flask routing. Wallet logic …
ratsmoothie Jul 31, 2023
31eedf0
Added db.get_all_wallets()
lawcode1203 Jul 31, 2023
45ff400
Fixed Wallet bug
lawcode1203 Jul 31, 2023
52b1211
Update index.html
lawcode1203 Jul 31, 2023
1acd64d
Added home GET method
lawcode1203 Jul 31, 2023
5c177b2
Added Wallet POST Method
lawcode1203 Jul 31, 2023
b1f1321
Update app.py
lawcode1203 Jul 31, 2023
fb8df90
Added janky home button to the wallet page
ratsmoothie Jul 31, 2023
83557b1
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
ratsmoothie Jul 31, 2023
2121931
Fixed /home GET bug
lawcode1203 Jul 31, 2023
13c4607
Added wallet deduction feature
lawcode1203 Jul 31, 2023
faf7db7
Bug fix for wallet creation.
lawcode1203 Jul 31, 2023
b5dd795
Added balance deduction
lawcode1203 Jul 31, 2023
acac8e5
products_manager.py
lawcode1203 Jul 31, 2023
98c6818
Minor fixes
lawcode1203 Aug 1, 2023
09e88c5
Fixed admin submit button bug
lawcode1203 Aug 1, 2023
baba12e
needed commit to be able to pull
ratsmoothie Aug 1, 2023
0ab5b64
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
ratsmoothie Aug 1, 2023
3560563
Username duplication catch
lawcode1203 Aug 1, 2023
e9601e4
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
ratsmoothie Aug 1, 2023
9729289
Fixed duplication checker bug
lawcode1203 Aug 1, 2023
6cc449f
Update app.py
lawcode1203 Aug 1, 2023
91911a8
Removed nonfunctional wallet button
lawcode1203 Aug 1, 2023
0108ae5
Created all test methods for inventory and system.
Erob494 Aug 1, 2023
ead7c4f
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
lawcode1203 Aug 1, 2023
cada786
Added inventory tests
lawcode1203 Aug 8, 2023
de9ae75
Inventory tests completed.
Erob494 Aug 8, 2023
049246a
created and started review tests file
Erob494 Aug 8, 2023
0d69795
Merge branch 'main' of https://github.com/lawcode1203/onlineStoreTemp…
ratsmoothie Aug 8, 2023
b4041a6
reviewed tests.
ratsmoothie Aug 8, 2023
72df103
Create lwoods14_review.md
lawcode1203 Aug 8, 2023
3af0c13
Bug fixes
lawcode1203 Aug 10, 2023
062faa7
Update passwords.txt
lawcode1203 Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
92 changes: 86 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
products = db.get_full_inventory()
sessions = Sessions()
sessions.add_new_session(username, db)

wallets = db.get_all_wallets()

@app.route('/')
def index_page():
Expand Down Expand Up @@ -58,15 +58,21 @@ def login():
- sessions: adds a new session to the sessions object

"""
global username
username = request.form['username']
password = request.form['password']
if login_pipeline(username, password):
sessions.add_new_session(username, db)
return render_template('home.html', products=products, sessions=sessions)
db.create_wallet(username, 0)
return render_template('home.html', products=products, sessions=sessions, username=username)
else:
print(f"Incorrect username ({username}) or password ({password}).")
return render_template('index.html')
username = 'default'
return render_template('index.html', products=products, sessions=sessions, username=username)

@app.route('/home', methods=['GET'])
def home():
return render_template("home.html",products=products, sessions=sessions, username=username)

@app.route('/register')
def register_page():
Expand All @@ -82,6 +88,44 @@ def register_page():
return render_template('register.html')


@app.route('/admin')
def admin_page():
"""
Renders the admin page when the user is at the `/admin` endpoint.

args:
- None

returns:
- None
"""
auth_level = sessions.get_session(username).auth_level
auth_level = 1 # Not good security
if auth_level == 0: #The user does not have admin privelages
return render_template('admin.html', message = "Access Denied. Not authorized to access this page.", username=username, products=[], sessions=sessions, auth_level=auth_level)
elif auth_level == 1:
return render_template("admin.html", message = "Product Management", username=username, products=products, sessions=sessions, auth_level=auth_level)

@app.route('/admin',methods=['POST'])
def admin():
"""
Sets the price of the products after price selection
"""

global products

for product in products:
price_string = request.form[str(product['id'])]
try:
new_price = float(price_string)
db.set_item_price(product['id'], new_price)
except ValueError: #No new value was passed
pass

products = db.get_full_inventory()
return render_template('admin.html', message='Your changes have been saved.')


@app.route('/register', methods=['POST'])
def register():
"""
Expand All @@ -104,7 +148,10 @@ def register():
last_name = request.form['last_name']
salt, key = hash_password(password)
update_passwords(username, key, salt)
db.insert_user(username, key, email, first_name, last_name)
if db.get_email_by_username(username) == None: # A user does not already exist with that username
db.insert_user(username, key, email, first_name, last_name)
else:
print(f"A user already exists with the username {username}")
return render_template('index.html')


Expand Down Expand Up @@ -132,10 +179,43 @@ def checkout():
user_session.add_new_item(
item['id'], item['item_name'], item['price'], count)

user_session.submit_cart()
if db.get_wallet_amount_username(username)[0]['amount'] > user_session.total_cost:
user_session.submit_cart()
db.increment_wallet_by_username(username, -1 * user_session.total_cost)
return render_template('checkout.html', order=order, sessions=sessions, total_cost=user_session.total_cost)
else:
return render_template('checkout.html', order=order, sessions=sessions, total_cost=" - Purchase failed due to not enough funds.")

return render_template('checkout.html', order=order, sessions=sessions, total_cost=user_session.total_cost)
@app.route("/wallet", methods=['GET'])
def wallet():
"""
Renders the wallet page when the user is at the `/wallet` endpoint with a GET request.

args:
- None

returns:
- None

modifies:
- None

"""
# Add wallet logic here
wallet_amount_json = db.get_wallet_amount_username(username)
if len(wallet_amount_json) > 0:
wallet_amount = wallet_amount_json[0]['amount']
else:
wallet_amount=0
# Render wallet.html
return render_template('wallet.html',balance=wallet_amount, username=username)

@app.route("/wallet", methods=['POST'])
def wallet_increment():
db.increment_wallet_by_username(username, 10)
wallet_amount_json = db.get_wallet_amount_username(username)
wallet_amount = wallet_amount_json[0]['amount']
return render_template('wallet.html',balance=wallet_amount, username=username)

if __name__ == '__main__':
app.run(debug=True, host=HOST, port=PORT)
3 changes: 3 additions & 0 deletions authentication/classes.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@startuml classes
set namespaceSeparator none
@enduml
7 changes: 6 additions & 1 deletion authentication/passwords.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
aturing:0d911297a1e34f4fcce78537f9aaa66a:b93727798b520dc10d145b53909c061f082ff14cd5f8cb4ab24c3b71bfa57d7e12e1296029be74c06a0d91ba32756f9fc978047fbe7232be67f94dfc1de9ced9
dritchie:e11d3b1a66b1ad362223c30b78138519:67aff785bd17ac24448d491926ff7aadd8fa75e51a2f7a9bfc31889bad0adcd2989061a27ccd9eff9e5e31f2bc14b5c193727e116dc8dc48259acb3919171cd4
llamport:89d0e5fe8d06ec113839c8f319d7033e:9171d14954eeda4e70777c23d98e349818125cdaeb884ff97ebf8cc0a9c7778f54ce394256588148132a03ebea891e44077c659e6c0132fa87a8cf77e436ae11
bliskov:e71dda285effa69e1c29ac810fe7a986:1e4b9ae956cad1385cfa6fffd8323dd16c3fe18c54e6447e49bddef2138d042e84e1505a541c6ef19a5026e684b2559efd366145870a0a8d4d4173c0877f6cd2
bliskov:e71dda285effa69e1c29ac810fe7a986:1e4b9ae956cad1385cfa6fffd8323dd16c3fe18c54e6447e49bddef2138d042e84e1505a541c6ef19a5026e684b2559efd366145870a0a8d4d4173c0877f6cd2
meap:0dad66db4864112a1ce2cd3a23a5eac2:3010cc4ff80196812ab998ea027d7b8e47c669c6d81e916613b85558ffabe690ef8d0be48fbcf7b640b4d62d359d863160abb19ae6cc7463e91a64129f1347abjoe:133340b956a3949e10651b82f40cc1d2:06cac2f8f677fbec167eafa866adb1de1781e0f4ef12f7d504c9b3c45f06f4fce3fea6d8b8f487ba1ff8af09336cd65d104de14d94656f7a278cf38c83ffc019
test:8fa663125c2bb4ad85cf3e9308be4b13:6b1e72b8ce311da2f95381870454679ad5bb31f108255995890e3fff7ce8c0dfe231e26aecf56fb9884a0a965ba6a27fbf1948583e4382a07fe610f33490f26d
data:55421ca1d83f93809ee70d371d04254b:468795c514daab3c68ee06b3b80b1fdceebf9929b688300b64ed1e4a9472173a670249dcc68ec9e0e977c653cffad2396f3821610cc68a243ad37da447d3c4db
demo:647a4b6b833fe6bca39ae1c2d656ff09:80caf1f1a3fe942bffd71e0284af6a3cd98a4a4e177158561f5ad7e6ecb6b683572046c2a8ee5c293e1b3cf4cf731a0ffc06467e793a259c0dbfd7d7edecc4af
meta:fc6bc4c18ad70f7eaa652cc836f190f6:de7ee32d82018de30a8a5fa7f00f808528f0efe9114af2bac416ff4471fe68ca18c1b06d64736573aa47ba206100e01ef7dd2be8ce2e386553db8ca7d0a84467
3 changes: 2 additions & 1 deletion core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class UserSession:
- db: The database to use.
"""

def __init__(self, username: str, db: Database):
def __init__(self, username: str, db: Database, auth_level = 0):
self.username = username
self.total_cost = 0
self.date = None
self.db = db
self.cart = self.empty_cart()
self.auth_level = auth_level

def empty_cart(self) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def dict_factory(cursor: sqlite3.Cursor, row: tuple) -> dict:
return row_dict


def calculate_cost(price: int, quantity: int, discount: float = 0.0, tax_rate: float = 0.05) -> float:
def calculate_cost(price: float, quantity: int, discount: float = 0.0, tax_rate: float = 0.05) -> float:
"""
Calculates the cost of an item.

Expand Down
48 changes: 46 additions & 2 deletions database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, database_path: str = "store_records.db") -> None:
# ----------------- INVENTORY ----------------
# --------------------------------------------

def insert_new_item(self, item_name: str, price: int, info: str) -> None:
def insert_new_item(self, item_name: str, price: int, info: str, stock=100, image_url="static/images/banana.jpeg", category="Food") -> None:
"""
Inserts a new item_item into the database.

Expand All @@ -40,7 +40,7 @@ def insert_new_item(self, item_name: str, price: int, info: str) -> None:
- None
"""
self.cursor.execute(
"INSERT INTO inventory (item_name, price, info) VALUES (?, ?, ?)", (item_name, price, info))
"INSERT INTO inventory (item_name, price, info, stock, image_url, category) VALUES (?, ?, ?, ?, ?, ?)", (item_name, price, info, stock, image_url, category))
self.connection.commit()

# ------ Getter methods ------
Expand Down Expand Up @@ -246,6 +246,17 @@ def set_item_category(self, item_id: int, new_category: str):
"UPDATE inventory SET category = ? WHERE id = ?", (new_category, item_id))
self.connection.commit()

# ------ Deleter methods -----
def delete_item_id(self, item_id: int):
"""
Deletes an item from the inventory based on its id.
"""

self.cursor.execute(
"DELETE FROM inventory WHERE id = ?", (item_id, )
)
self.connection.commit()

# --------------------------------------------
# ------------------ Users -------------------
# --------------------------------------------
Expand Down Expand Up @@ -399,6 +410,7 @@ def set_last_name(self, username: str, new_last_name: str):
self.cursor.execute(
"UPDATE users SET last_name = ? WHERE username = ?", (new_last_name, username))
self.connection.commit()


# --------------------------------------------
# ------------------ Sales -------------------
Expand Down Expand Up @@ -624,6 +636,8 @@ def get_sales_by_cost_range(self, start_cost: float, end_cost: float):
"SELECT * FROM sales WHERE cost BETWEEN ? AND ?", (start_cost, end_cost))
return self.cursor.fetchall()



# ------ Setter methods ------

def set_sale_transaction_id(self, sale_id: int, new_transaction_id: int):
Expand Down Expand Up @@ -719,3 +733,33 @@ def set_sale_cost(self, sale_id: int, discount: float = 0, tax: float = 0.05):
self.cursor.execute(
"UPDATE sales SET cost = ? WHERE id = ?", (new_cost, sale_id))
self.connection.commit()

# --------------------------------------------
# ------------------ Wallet ------------------
# --------------------------------------------
def create_wallet(self, username, amount: int):
if self.get_wallet_amount_username(username) == []:
self.cursor.execute(
"INSERT INTO wallets (username, amount) VALUES (?, ?)", (username, amount))
self.connection.commit()

def get_wallet_amount_id(self, wallet_id):
self.cursor.execute(
"SELECT * FROM wallets WHERE wallet_id = ?", (wallet_id,))
return self.cursor.fetchall()

def get_wallet_amount_username(self, username):
self.cursor.execute(
"SELECT * FROM wallets WHERE username = ?", (username,))
return self.cursor.fetchall()

def get_all_wallets(self):
self.cursor.execute(
"SELECT * FROM wallets")
return self.cursor.fetchall()

def increment_wallet_by_username(self, username, change_amount):
current_amount = self.get_wallet_amount_username(username)[0]['amount']
self.cursor.execute(
"UPDATE wallets SET amount = ? WHERE username = ?", (current_amount + change_amount, username))
self.connection.commit()
6 changes: 6 additions & 0 deletions database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ CREATE TABLE sales (
FOREIGN KEY (item_id) REFERENCES inventory(id)
);

CREATE TABLE wallets (
wallet_id INTEGER PRIMARY KEY AUTOINCREMENT,
username VARCHAR(255) NOT NULL,
amount INTEGER NOT NULL,
FOREIGN KEY (username) REFERENCES users(username)
);
15 changes: 12 additions & 3 deletions database/starting_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ INSERT into `users` (`username`, `password_hash`, `email`, `first_name`, `last_n
VALUES ('bliskov', '1e4b9ae956cad1385cfa6fffd8323dd16c3fe18c54e6447e49bddef2138d042e84e1505a541c6ef19a5026e684b2559efd366145870a0a8d4d4173c0877f6cd2', 'barbara@thor.com', 'Barbara', 'Liskov');

INSERT into `inventory` (`item_name`, `info`, `price`, `stock`, `image_url`, `category`)
VALUES ('Apples', 'An edible cultivation of the Malus genus.', 2.00, 100, 'static/images/apple.jpeg', 'Fruit');
VALUES ('Latte', 'Steamed milk and espresso.', 5.00, 100, 'static/images/488latte.png', 'Coffee');

INSERT into `inventory` (`item_name`, `info`, `price`, `stock`, `image_url`, `category`)
VALUES ('Bananas', 'A long curved fruit which grows in clusters and has soft pulpy flesh and yellow skin when ripe.', 1.00, 100, 'static/images/banana.jpeg', 'Fruit');
VALUES ('Iced Latte', 'Milk and espresso, served over ice.', 4.00, 100, 'static/images/488icedlatte.jpeg', 'Coffee');

INSERT into `inventory` (`item_name`, `info`, `price`, `stock`, `image_url`, `category`)
VALUES ('Mangos', 'The best fruit on the planet.', 4.00, 100, 'static/images/mango.jpeg', 'Fruit');
VALUES ('Filter Coffee', 'Made via pour over.', 3.00, 100, 'static/images/488coffee.jpeg', 'Coffee');

INSERT into `inventory` (`item_name`, `info`, `price`, `stock`, `image_url`, `category`)
VALUES ('Nitro Cold Brew', 'Brewed cold and flushed with nitrogen to give it a heady, beer-like foam.', 6.00, 100, 'static/images/488nitro.jpeg', 'Coffee');

INSERT into `inventory` (`item_name`, `info`, `price`, `stock`, `image_url`, `category`)
VALUES ('Matcha Latte', 'Steamed milk over powdered green tea.', 5.00, 100, 'static/images/488matcha.jpeg', 'Tea');

INSERT into `inventory` (`item_name`, `info`, `price`, `stock`, `image_url`, `category`)
VALUES ('Tea', 'Black tea.', 3.00, 100, 'static/images/488tea.jpeg', 'Tea');

INSERT into `sales` (`transaction_id`, `username`, `item_id`, `quantity`, `sale_date`, `cost`)
VALUES ('1', 'aturing', '1', 10, '2022-12-21 7:30:30', 5.50);
Expand Down
Binary file added docs/diagrams/cases/administrator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions docs/diagrams/cases/administrator.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@startuml administrator
left to right direction
actor Admin
rectangle "System" as system {
(Login)
(View Orders)
(View Profile)
(View Product)
(Edit Product)
(Logout)
}
Admin --> (Login)
Admin --> (View Orders)
Admin --> (View Profile)
Admin --> (Logout)
Admin --> (View Product)
Admin --> (Edit Product)

@enduml
Binary file added docs/diagrams/cases/customer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/diagrams/cases/customer.puml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ left to right direction
actor Customer
rectangle "System" as system {
(Login)
(Place Order)
(Cancel Order)
(Edit Order)
(Register)
(View Cart)
(View Items)
Expand All @@ -17,4 +20,7 @@ Customer --> (View Items)
Customer --> (View Orders)
Customer --> (View Profile)
Customer --> (Logout)
Customer --> (Place Order)
Customer --> (Edit Order)
Customer --> (Cancel Order)
@enduml
Binary file added docs/diagrams/sequences/admin_login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docs/diagrams/sequences/admin_login.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@startuml admin_login
actor Admin order 10
boundary "System" as system order 20
database "Products" as products order 50
control "Wallet Manager" as wallet order 60
control "Sessions" as sessions order 40
control "Authentication" as auth order 30
Admin -> system : Login request
activate system
system -> auth : admin_login_pipeline(username, password)
activate auth
auth --> system : True
system -> sessions : admin_add_new_session(username, db)
sessions --> system: None
sessions -> products : Grant Admin access
activate products
sessions -> wallet : Grant Admin access
activate wallet
wallet --> system : Access Granted
products --> system : Access Granted
deactivate wallet
deactivate products
deactivate sessions
system -> Admin : Display information
deactivate system


@enduml

Binary file added docs/diagrams/sequences/cancel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions docs/diagrams/sequences/cancel.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@startuml cancel
actor Customer order 10
boundary "System" as system order 30
database "Products" as products order 40
control "Wallet Manager" as wallet order 50
control "Sessions" as sessions order 20
Customer -> sessions : Cancel requests
activate sessions
sessions -> system : Forward cancel
activate system
system -> system : Check status (security)
system -> wallet : Increase balance
activate wallet
wallet -> wallet : Internal increment
wallet -> system : Balance confirmation
deactivate wallet
system -> products : Quantity increment
activate products
products -> products : Quantity increment
deactivate products
system -> sessions : Confirmation
deactivate system
sessions -> Customer : Confirmation forward
deactivate sessions
@enduml
Binary file added docs/diagrams/sequences/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading