Skip to content

Commit

Permalink
Added search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnQuitno committed Apr 11, 2019
1 parent a5e76f5 commit fd9c22e
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/UserInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def CheckCredentials(username,password):

def AddFolder(username):
try:
newFolder = os.getcwd() + "static/UserPictures/" + username
newFolder = os.getcwd() + "/static/UserPictures/" + username
os.mkdir(newFolder)
except FileExistsError:
pass
3 changes: 3 additions & 0 deletions app/UserInfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ bob 9f9d51bc70ef21ca5c14f307980a29d8
Jerry dbaf60f3a397e1d27630a459c1700ea7
hirsh d988318ebac9f246609d6866a10784ae
ryan 10c7ccc7a4f0aff03c915c485565b9da
buddy e338bc584bd1c7f87b8a5bf70a3cf80e
tate c8c01893d9bc804c03b7f7ff190fea79
joe 8ff32489f92f33416694be8fdc2d4c22
Binary file modified app/__pycache__/UserInfo.cpython-37.pyc
Binary file not shown.
17 changes: 13 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os.path
import json
import hashlib
from UserInfo import AddUser, AddFolder, CheckCredentials
from UserInfo import AddUser, AddFolder, CheckCredentials,UserExists
from werkzeug.utils import secure_filename

app = Flask(__name__)
Expand Down Expand Up @@ -58,7 +58,7 @@ def signup():
@app.route('/landing')
def landing():
if g.user:
return render_template('landing.html')
return render_template('landing.html', user=g.user)
return redirect(url_for('login'))

@app.before_request
Expand Down Expand Up @@ -94,10 +94,12 @@ def upload_page():

@app.route('/user/<username>/images')
def getUserImages(username):
if not g.user:
if not UserExists(username):
return "False"
elif not g.user:
return redirect(url_for('login'))

files = glob(os.path.join('static', 'UserPictures', username, '*'))
print(os.path.join('static', 'UserPictures', username, '*'))
return json.dumps(files)

@app.route('/user/images')
Expand All @@ -106,5 +108,12 @@ def getCurrentUserImages():
return redirect(url_for('login'))
return getUserImages(g.user)

@app.route('/search/<username>')
def search(username):
print (username)
if g.user:
return render_template('search.html',user=username)
return redirect(url_for('login'))

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
48 changes: 48 additions & 0 deletions app/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ function logOut()
window.location.href = '/dropsession';
}

function returnHome()
{
window.location.href = '/landing';
}

function uploadImage()
{
document.querySelector('#upload').style.visibility = "visible";
Expand All @@ -161,6 +166,7 @@ function fetchImages()
type: "GET",
url: '/user/images',
success: function (response) {
console.log(response)
imagesDiv = document.querySelector("#images");
for (let image of JSON.parse(response)) {
let newImg = document.createElement("img");
Expand All @@ -170,9 +176,51 @@ function fetchImages()
}
});
}
function fetchUserImages(user)
{
$.ajax({
type: "GET",
url: '/user/' + user + '/images',
success: function (response) {
console.log(response)
imagesDiv = document.querySelector("#images");
for (let image of JSON.parse(response)) {
let newImg = document.createElement("img");
newImg.src = "../" + image;
imagesDiv.appendChild(newImg);
}
}
});
}

function searchUsername()
{
let targetUser = document.getElementById("searchUser").value
$.ajax({
type: "GET",
asyn: false,
url: '/search/' + targetUser,
success: function(response){
//goes to landing after signup
if(response=="False")
{
window.alert("Username does not exist");
}
else {
window.location.href = '/search/' + targetUser

}
}
})
}
window.onload = () => {
if (window.location.pathname == '/landing') {
fetchImages();
}
pathArr = window.location.pathname.split('/')
if (pathArr[1] == 'search') {
fetchUserImages(pathArr[2]);
}


}
4 changes: 4 additions & 0 deletions app/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ button:hover, a:hover {
background-color: white;
color: #3c3c3c;
}

#search {
width: 5%;
}
7 changes: 5 additions & 2 deletions app/templates/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
<body>
<div class="topBar">
<img id="profilePic" src="../static/default.jpg" onclick="logOut()"></img>
Welcome, <span id="username">Test User</span>!<br>
<input type="text" placeholder = "Input another User"></input><br><br>
Welcome, <span id="username">{{ user }}</span>!<br>
<form onsubmit="searchUsername()">
<input type="text" id="searchUser" placeholder = "Input another User">
<input type="submit" id="search" value="Search"></input><br><br>
</form>

<!--text input field for image urls? Or something else?-->
<button type="button" id="image" onclick="uploadImage()">Add Image</button>
Expand Down
35 changes: 35 additions & 0 deletions app/templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>Dogstagram</title>
<!--<link rel='shortcut icon' href='../index.ico' type='image/x-icon'/>-->
<link rel="stylesheet" type="text/css" href="../static/style.css"/>

<!-- Add the Firebase and Cloud Firestore libraries to app -->
<script src="https://www.gstatic.com/firebasejs/5.9.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.2/firebase-firestore.js"></script>

<!-- include jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="topBar">
<img id="profilePic" src="../static/default.jpg" onclick="logOut()"></img>
Welcome to <span id="username"> {{ user }} </span>'s page!<br>
<br><button type="button" onclick="returnHome()">Return Home</button>

<div id="upload" style="visibility: hidden;">
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="image" id="image">
<input type="submit" value="Upload!">
</form>
</div>
</div>
<br>
<div id="message">&nbsp</div>
<div id="images">

</div>
<script src = "../static/main.js" defer></script>
</body>
</html>

0 comments on commit fd9c22e

Please sign in to comment.