From fd9c22e5877e43eb21eed64b9a8497e7bbf600e7 Mon Sep 17 00:00:00 2001 From: JohnQuitno Date: Thu, 11 Apr 2019 16:46:54 -0500 Subject: [PATCH] Added search functionality --- app/UserInfo.py | 2 +- app/UserInfo.txt | 3 ++ app/__pycache__/UserInfo.cpython-37.pyc | Bin 1294 -> 1274 bytes app/main.py | 17 +++++++-- app/static/main.js | 48 ++++++++++++++++++++++++ app/static/style.css | 4 ++ app/templates/landing.html | 7 +++- app/templates/search.html | 35 +++++++++++++++++ 8 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 app/templates/search.html diff --git a/app/UserInfo.py b/app/UserInfo.py index 3eb0f5f..732b081 100644 --- a/app/UserInfo.py +++ b/app/UserInfo.py @@ -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 \ No newline at end of file diff --git a/app/UserInfo.txt b/app/UserInfo.txt index c3395a1..d388a4a 100644 --- a/app/UserInfo.txt +++ b/app/UserInfo.txt @@ -6,3 +6,6 @@ bob 9f9d51bc70ef21ca5c14f307980a29d8 Jerry dbaf60f3a397e1d27630a459c1700ea7 hirsh d988318ebac9f246609d6866a10784ae ryan 10c7ccc7a4f0aff03c915c485565b9da +buddy e338bc584bd1c7f87b8a5bf70a3cf80e +tate c8c01893d9bc804c03b7f7ff190fea79 +joe 8ff32489f92f33416694be8fdc2d4c22 diff --git a/app/__pycache__/UserInfo.cpython-37.pyc b/app/__pycache__/UserInfo.cpython-37.pyc index 4e3014dec1696f43d4fe57334e6192b5b1ea70b4..6477980cec0dc1120eea9b120ad63f76a9113805 100644 GIT binary patch delta 61 zcmeC<`o+oX#LLUY00c4qYh&~`@|rM8nLAs>gche36~}nxXXFKzW|rjT$GEyW2gh$N PV7$%5B&t8zhvg6e1v?T` delta 81 zcmeyx*~i7}#LLUY00fhq*2d^</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') @@ -106,5 +108,12 @@ def getCurrentUserImages(): return redirect(url_for('login')) return getUserImages(g.user) +@app.route('/search/') +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) diff --git a/app/static/main.js b/app/static/main.js index e7dc26f..63d6243 100644 --- a/app/static/main.js +++ b/app/static/main.js @@ -150,6 +150,11 @@ function logOut() window.location.href = '/dropsession'; } +function returnHome() +{ + window.location.href = '/landing'; +} + function uploadImage() { document.querySelector('#upload').style.visibility = "visible"; @@ -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"); @@ -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]); + } + + } \ No newline at end of file diff --git a/app/static/style.css b/app/static/style.css index e0efbc6..faf85e8 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -71,3 +71,7 @@ button:hover, a:hover { background-color: white; color: #3c3c3c; } + +#search { + width: 5%; +} \ No newline at end of file diff --git a/app/templates/landing.html b/app/templates/landing.html index c6019a0..9441ba4 100644 --- a/app/templates/landing.html +++ b/app/templates/landing.html @@ -15,8 +15,11 @@
- Welcome, Test User!
-

+ Welcome, {{ user }}!
+
+ +

+
diff --git a/app/templates/search.html b/app/templates/search.html new file mode 100644 index 0000000..c4a401d --- /dev/null +++ b/app/templates/search.html @@ -0,0 +1,35 @@ + + + + Dogstagram + + + + + + + + + + + +
+ + Welcome to {{ user }} 's page!
+
+ + +
+
+
 
+
+ +
+ + +