Skip to content

Commit

Permalink
Added account settings
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshShah1997 committed Aug 14, 2016
1 parent 9c2084e commit f6fcd3d
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 17 deletions.
Binary file modified database.db
Binary file not shown.
45 changes: 45 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,51 @@ def displayCategory():
data = parse(data)
return render_template('displayCategory.html', data=data, loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems, categoryName=categoryName)

@app.route("/account/profile")
def profileHome():
if 'email' not in session:
return redirect(url_for('root'))
loggedIn, firstName, noOfItems = getLoginDetails()
return render_template("profileHome.html", loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems)

@app.route("/account/profile/edit")
def editProfile():
if 'email' not in session:
return redirect(url_for('root'))
loggedIn, firstName, noOfItems = getLoginDetails()
with sqlite3.connect('database.db') as conn:
cur = conn.cursor()
cur.execute("SELECT userId, email, firstName, lastName, address1, address2, zipcode, city, state, country, phone FROM users WHERE email = '" + session['email'] + "'")
profileData = cur.fetchone()
conn.close()
return render_template("editProfile.html", profileData=profileData, loggedIn=loggedIn, firstName=firstName, noOfItems=noOfItems)

@app.route("/updateProfile", methods=["GET", "POST"])
def updateProfile():
if request.method == 'POST':
email = request.form['email']
firstName = request.form['firstName']
lastName = request.form['lastName']
address1 = request.form['address1']
address2 = request.form['address2']
zipcode = request.form['zipcode']
city = request.form['city']
state = request.form['state']
country = request.form['country']
phone = request.form['phone']
with sqlite3.connect('database.db') as con:
try:
cur = con.cursor()
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))

con.commit()
msg = "Saved Successfully"
except:
con.rollback()
msg = "Error occured"
con.close()
return redirect(url_for('editProfile'))

@app.route("/loginForm")
def loginForm():
if 'email' in session:
Expand Down
41 changes: 36 additions & 5 deletions static/css/topStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,46 @@
float: left;
}

#displayUserId {
.dropbtn {
background-color: black;
color: white;
margin-top: 20px;
margin-bottom: 20px;
margin-left: 20px;
margin-right: 20px;
padding: 16px;
font-size: 15px;
border: none;
cursor: pointer;
}

.dropdown {
position: relative;
float: left;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
font-size: 14px;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
display: block;
}

.dropdown:hover .dropbtn {
background-color: gray;
}

#signInButton {
color: yellow;
margin-top: 20px;
Expand Down
11 changes: 8 additions & 3 deletions templates/cart.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
<a class="link" href="/loginForm">Sign In</a>
</div>
{% else %}
<div id="displayUserId">Hello, <br>{{firstName}}</div>
<div id="signInButton">
<a class="link" href="/logout">Sign Out</a>
<div class="dropdown">
<button class="dropbtn">Hello, <br>{{firstName}}</button>
<div class="dropdown-content">
<a href="/account/orders">Your orders</a>
<a href="/account/profile">Your profile</a>
<hr>
<a href="/logout">Sign Out</a>
</div>
</div>
{% endif %}
<div id="kart">
<a class="link" href="/cart">
Expand Down
11 changes: 8 additions & 3 deletions templates/displayCategory.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
<a class="link" href="/loginForm">Sign In</a>
</div>
{% else %}
<div id="displayUserId">Hello, <br>{{firstName}}</div>
<div id="signInButton">
<a class="link" href="/logout">Sign Out</a>
<div class="dropdown">
<button class="dropbtn">Hello, <br>{{firstName}}</button>
<div class="dropdown-content">
<a href="/account/orders">Your orders</a>
<a href="/account/profile">Your profile</a>
<hr>
<a href="/logout">Sign Out</a>
</div>
</div>
{% endif %}
<div id="kart">
Expand Down
59 changes: 59 additions & 0 deletions templates/editProfile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Edit Profile </title>
<link rel="stylesheet" href={{ url_for('static', filename='css/editProfile.css') }} />
<link rel="stylesheet" href={{ url_for('static', filename='css/topStyle.css') }} />
</head>
<body>
<div id="title">
<a href="/">
<img id="logo" src= {{ url_for('static', filename='images/logo.png') }} />
</a>
<form>
<input id="searchBox" type="text" name="searchQuery">
<input id="searchButton" type="submit" value="Search">
</form>

{% if not loggedIn %}
<div id="signInButton">
<a class="link" href="/loginForm">Sign In</a>
</div>
{% else %}
<div class="dropdown">
<button class="dropbtn">Hello, <br>{{firstName}}</button>
<div class="dropdown-content">
<a href="/account/orders">Your orders</a>
<a href="/account/profile">Your profile</a>
<hr>
<a href="/logout">Sign Out</a>
</div>
</div>
{% endif %}
<div id="kart">
<a class="link" href="/cart">
<img src={{url_for('static', filename='images/shoppingCart.png')}} id="cartIcon" />
CART {{noOfItems}}
</a>
</div>
</div>

<div class="display">
<h2>Edit profile</h2>
<form action="/updateProfile" method="POST">
<p>Email:<input type="email" name="email" value={{profileData[1]}} readonly="readonly"></p>
<p>First Name:<input type="text" name="firstName" value={{profileData[2]}}></p>
<p>Last Name: <input type="text" name="lastName" value={{profileData[3]}}></p>
<p>Address 1: <input type="text" name="address1" value={{profileData[4]}}></p>
<p>Address 2: <input type="text" name="address2" value={{profileData[5]}}></p>
<p>Zip Code: <input type="text" name="zipcode" value={{profileData[6]}}></p>
<p>City: <input type="text" name="city" value={{profileData[7]}}></p>
<p>State: <input type="text" name="state" value={{profileData[8]}}></p>
<p>Country: <input type="text" name="country" value={{profileData[9]}}></p>
<p>Phone Number: <input type="text" name="phone" value={{profileData[10]}}></p>
<input type="submit" value="Save">
</form>
</div>
</body>
</html>

11 changes: 8 additions & 3 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
<a class="link" href="/loginForm">Sign In</a>
</div>
{% else %}
<div id="displayUserId">Hello, <br>{{firstName}}</div>
<div id="signInButton">
<a class="link" href="/logout">Sign Out</a>
<div class="dropdown">
<button class="dropbtn">Hello, <br>{{firstName}}</button>
<div class="dropdown-content">
<a href="/account/orders">Your orders</a>
<a href="/account/profile">Your profile</a>
<hr>
<a href="/logout">Sign Out</a>
</div>
</div>
{% endif %}
<div id="kart">
Expand Down
11 changes: 8 additions & 3 deletions templates/productDescription.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
<a class="link" href="/loginForm">Sign In</a>
</div>
{% else %}
<div id="displayUserId">Hello, <br>{{firstName}}</div>
<div id="signInButton">
<a class="link" href="/logout">Sign Out</a>
<div class="dropdown">
<button class="dropbtn">Hello, <br>{{firstName}}</button>
<div class="dropdown-content">
<a href="/account/orders">Your orders</a>
<a href="/account/profile">Your profile</a>
<hr>
<a href="/logout">Sign Out</a>
</div>
</div>
{% endif %}
<div id="kart">
Expand Down
48 changes: 48 additions & 0 deletions templates/profileHome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Profile Home</title>
<link rel="stylesheet" href={{ url_for('static', filename='css/profileHome.css') }} />
<link rel="stylesheet" href={{ url_for('static', filename='css/topStyle.css') }} />
</head>
<body>
<div id="title">
<a href="/">
<img id="logo" src= {{ url_for('static', filename='images/logo.png') }} />
</a>
<form>
<input id="searchBox" type="text" name="searchQuery">
<input id="searchButton" type="submit" value="Search">
</form>

{% if not loggedIn %}
<div id="signInButton">
<a class="link" href="/loginForm">Sign In</a>
</div>
{% else %}
<div class="dropdown">
<button class="dropbtn">Hello, <br>{{firstName}}</button>
<div class="dropdown-content">
<a href="/account/orders">Your orders</a>
<a href="/account/profile">Your profile</a>
<hr>
<a href="/logout">Sign Out</a>
</div>
</div>
{% endif %}
<div id="kart">
<a class="link" href="/cart">
<img src={{url_for('static', filename='images/shoppingCart.png')}} id="cartIcon" />
CART {{noOfItems}}
</a>
</div>
</div>

<div class="display">
<a href="/account/profile/view">View Profile</a>
<a href="/account/profile/edit">Edit Profile</a>
<a href="/account/profile/changePassword">Change password</a>
</div>
</body>
</html>

0 comments on commit f6fcd3d

Please sign in to comment.