Skip to content

Commit f6fcd3d

Browse files
committed
Added account settings
1 parent 9c2084e commit f6fcd3d

File tree

9 files changed

+220
-17
lines changed

9 files changed

+220
-17
lines changed

database.db

0 Bytes
Binary file not shown.

main.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,51 @@ def displayCategory():
111111
data = parse(data)
112112
return render_template('displayCategory.html', data=data, loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems, categoryName=categoryName)
113113

114+
@app.route("/account/profile")
115+
def profileHome():
116+
if 'email' not in session:
117+
return redirect(url_for('root'))
118+
loggedIn, firstName, noOfItems = getLoginDetails()
119+
return render_template("profileHome.html", loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems)
120+
121+
@app.route("/account/profile/edit")
122+
def editProfile():
123+
if 'email' not in session:
124+
return redirect(url_for('root'))
125+
loggedIn, firstName, noOfItems = getLoginDetails()
126+
with sqlite3.connect('database.db') as conn:
127+
cur = conn.cursor()
128+
cur.execute("SELECT userId, email, firstName, lastName, address1, address2, zipcode, city, state, country, phone FROM users WHERE email = '" + session['email'] + "'")
129+
profileData = cur.fetchone()
130+
conn.close()
131+
return render_template("editProfile.html", profileData=profileData, loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems)
132+
133+
@app.route("/updateProfile", methods=["GET", "POST"])
134+
def updateProfile():
135+
if request.method == 'POST':
136+
email = request.form['email']
137+
firstName = request.form['firstName']
138+
lastName = request.form['lastName']
139+
address1 = request.form['address1']
140+
address2 = request.form['address2']
141+
zipcode = request.form['zipcode']
142+
city = request.form['city']
143+
state = request.form['state']
144+
country = request.form['country']
145+
phone = request.form['phone']
146+
with sqlite3.connect('database.db') as con:
147+
try:
148+
cur = con.cursor()
149+
cur.execute('UPDATE users SET firstName = ?, lastName = ?, address1 = ?, address2 = ?, zipcode = ?, city = ?, state = ?, country = ?, phone = ? WHERE email = ?', (firstName, lastName, address1, address2, zipcode, city, state, country, phone, email))
150+
151+
con.commit()
152+
msg = "Saved Successfully"
153+
except:
154+
con.rollback()
155+
msg = "Error occured"
156+
con.close()
157+
return redirect(url_for('editProfile'))
158+
114159
@app.route("/loginForm")
115160
def loginForm():
116161
if 'email' in session:

static/css/topStyle.css

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,46 @@
3333
float: left;
3434
}
3535

36-
#displayUserId {
36+
.dropbtn {
37+
background-color: black;
3738
color: white;
38-
margin-top: 20px;
39-
margin-bottom: 20px;
40-
margin-left: 20px;
41-
margin-right: 20px;
39+
padding: 16px;
40+
font-size: 15px;
41+
border: none;
42+
cursor: pointer;
43+
}
44+
45+
.dropdown {
46+
position: relative;
4247
float: left;
4348
}
4449

50+
.dropdown-content {
51+
display: none;
52+
position: absolute;
53+
background-color: #f9f9f9;
54+
min-width: 160px;
55+
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
56+
}
57+
58+
.dropdown-content a {
59+
font-size: 14px;
60+
color: black;
61+
padding: 12px 16px;
62+
text-decoration: none;
63+
display: block;
64+
}
65+
66+
.dropdown-content a:hover {background-color: #f1f1f1}
67+
68+
.dropdown:hover .dropdown-content {
69+
display: block;
70+
}
71+
72+
.dropdown:hover .dropbtn {
73+
background-color: gray;
74+
}
75+
4576
#signInButton {
4677
color: yellow;
4778
margin-top: 20px;

templates/cart.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
<a class="link" href="/loginForm">Sign In</a>
2121
</div>
2222
{% else %}
23-
<div id="displayUserId">Hello, <br>{{firstName}}</div>
24-
<div id="signInButton">
25-
<a class="link" href="/logout">Sign Out</a>
23+
<div class="dropdown">
24+
<button class="dropbtn">Hello, <br>{{firstName}}</button>
25+
<div class="dropdown-content">
26+
<a href="/account/orders">Your orders</a>
27+
<a href="/account/profile">Your profile</a>
28+
<hr>
29+
<a href="/logout">Sign Out</a>
2630
</div>
31+
</div>
2732
{% endif %}
2833
<div id="kart">
2934
<a class="link" href="/cart">

templates/displayCategory.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
<a class="link" href="/loginForm">Sign In</a>
2121
</div>
2222
{% else %}
23-
<div id="displayUserId">Hello, <br>{{firstName}}</div>
24-
<div id="signInButton">
25-
<a class="link" href="/logout">Sign Out</a>
23+
<div class="dropdown">
24+
<button class="dropbtn">Hello, <br>{{firstName}}</button>
25+
<div class="dropdown-content">
26+
<a href="/account/orders">Your orders</a>
27+
<a href="/account/profile">Your profile</a>
28+
<hr>
29+
<a href="/logout">Sign Out</a>
30+
</div>
2631
</div>
2732
{% endif %}
2833
<div id="kart">

templates/editProfile.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>Edit Profile </title>
5+
<link rel="stylesheet" href={{ url_for('static', filename='css/editProfile.css') }} />
6+
<link rel="stylesheet" href={{ url_for('static', filename='css/topStyle.css') }} />
7+
</head>
8+
<body>
9+
<div id="title">
10+
<a href="/">
11+
<img id="logo" src= {{ url_for('static', filename='images/logo.png') }} />
12+
</a>
13+
<form>
14+
<input id="searchBox" type="text" name="searchQuery">
15+
<input id="searchButton" type="submit" value="Search">
16+
</form>
17+
18+
{% if not loggedIn %}
19+
<div id="signInButton">
20+
<a class="link" href="/loginForm">Sign In</a>
21+
</div>
22+
{% else %}
23+
<div class="dropdown">
24+
<button class="dropbtn">Hello, <br>{{firstName}}</button>
25+
<div class="dropdown-content">
26+
<a href="/account/orders">Your orders</a>
27+
<a href="/account/profile">Your profile</a>
28+
<hr>
29+
<a href="/logout">Sign Out</a>
30+
</div>
31+
</div>
32+
{% endif %}
33+
<div id="kart">
34+
<a class="link" href="/cart">
35+
<img src={{url_for('static', filename='images/shoppingCart.png')}} id="cartIcon" />
36+
CART {{noOfItems}}
37+
</a>
38+
</div>
39+
</div>
40+
41+
<div class="display">
42+
<h2>Edit profile</h2>
43+
<form action="/updateProfile" method="POST">
44+
<p>Email:<input type="email" name="email" value={{profileData[1]}} readonly="readonly"></p>
45+
<p>First Name:<input type="text" name="firstName" value={{profileData[2]}}></p>
46+
<p>Last Name: <input type="text" name="lastName" value={{profileData[3]}}></p>
47+
<p>Address 1: <input type="text" name="address1" value={{profileData[4]}}></p>
48+
<p>Address 2: <input type="text" name="address2" value={{profileData[5]}}></p>
49+
<p>Zip Code: <input type="text" name="zipcode" value={{profileData[6]}}></p>
50+
<p>City: <input type="text" name="city" value={{profileData[7]}}></p>
51+
<p>State: <input type="text" name="state" value={{profileData[8]}}></p>
52+
<p>Country: <input type="text" name="country" value={{profileData[9]}}></p>
53+
<p>Phone Number: <input type="text" name="phone" value={{profileData[10]}}></p>
54+
<input type="submit" value="Save">
55+
</form>
56+
</div>
57+
</body>
58+
</html>
59+

templates/home.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
<a class="link" href="/loginForm">Sign In</a>
2121
</div>
2222
{% else %}
23-
<div id="displayUserId">Hello, <br>{{firstName}}</div>
24-
<div id="signInButton">
25-
<a class="link" href="/logout">Sign Out</a>
23+
<div class="dropdown">
24+
<button class="dropbtn">Hello, <br>{{firstName}}</button>
25+
<div class="dropdown-content">
26+
<a href="/account/orders">Your orders</a>
27+
<a href="/account/profile">Your profile</a>
28+
<hr>
29+
<a href="/logout">Sign Out</a>
30+
</div>
2631
</div>
2732
{% endif %}
2833
<div id="kart">

templates/productDescription.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
<a class="link" href="/loginForm">Sign In</a>
2121
</div>
2222
{% else %}
23-
<div id="displayUserId">Hello, <br>{{firstName}}</div>
24-
<div id="signInButton">
25-
<a class="link" href="/logout">Sign Out</a>
23+
<div class="dropdown">
24+
<button class="dropbtn">Hello, <br>{{firstName}}</button>
25+
<div class="dropdown-content">
26+
<a href="/account/orders">Your orders</a>
27+
<a href="/account/profile">Your profile</a>
28+
<hr>
29+
<a href="/logout">Sign Out</a>
30+
</div>
2631
</div>
2732
{% endif %}
2833
<div id="kart">

templates/profileHome.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>Profile Home</title>
5+
<link rel="stylesheet" href={{ url_for('static', filename='css/profileHome.css') }} />
6+
<link rel="stylesheet" href={{ url_for('static', filename='css/topStyle.css') }} />
7+
</head>
8+
<body>
9+
<div id="title">
10+
<a href="/">
11+
<img id="logo" src= {{ url_for('static', filename='images/logo.png') }} />
12+
</a>
13+
<form>
14+
<input id="searchBox" type="text" name="searchQuery">
15+
<input id="searchButton" type="submit" value="Search">
16+
</form>
17+
18+
{% if not loggedIn %}
19+
<div id="signInButton">
20+
<a class="link" href="/loginForm">Sign In</a>
21+
</div>
22+
{% else %}
23+
<div class="dropdown">
24+
<button class="dropbtn">Hello, <br>{{firstName}}</button>
25+
<div class="dropdown-content">
26+
<a href="/account/orders">Your orders</a>
27+
<a href="/account/profile">Your profile</a>
28+
<hr>
29+
<a href="/logout">Sign Out</a>
30+
</div>
31+
</div>
32+
{% endif %}
33+
<div id="kart">
34+
<a class="link" href="/cart">
35+
<img src={{url_for('static', filename='images/shoppingCart.png')}} id="cartIcon" />
36+
CART {{noOfItems}}
37+
</a>
38+
</div>
39+
</div>
40+
41+
<div class="display">
42+
<a href="/account/profile/view">View Profile</a>
43+
<a href="/account/profile/edit">Edit Profile</a>
44+
<a href="/account/profile/changePassword">Change password</a>
45+
</div>
46+
</body>
47+
</html>
48+

0 commit comments

Comments
 (0)