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
2 parents fd9c22e + 684236f commit 0b529a0
Show file tree
Hide file tree
Showing 84 changed files with 28,001 additions and 95 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/UserPictures/**
**/UserPictures/**

!app/static/UserPictures/.gitkeep
Binary file modified app/.DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions app/UserInfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import os

def AddUser(username, password):
"""Adds a new user to the database
Args:
username (str): The username of the new user
password (str): The password of the new user
Returns:
bool: Returns false if user already exists, true otherwise
"""
if UserExists(username):
return False
AddFolder(username)
Expand All @@ -11,6 +20,14 @@ def AddUser(username, password):
return True

def UserExists(username):
"""Checks whether user still exists
Args:
username (str): The username to check
Returns:
bool: Returns true if user with username exists already
"""
file = open("UserInfo.txt","r")
fileAsString = file.read()
arr = fileAsString.split('\n')
Expand All @@ -21,6 +38,15 @@ def UserExists(username):
return False

def CheckCredentials(username,password):
"""Checks if the username and password are valid
Args:
username (str): The username of the user to check
password (str): The password of the user to check
Returns:
bool: Returns true if username and password match database
"""
file = open("UserInfo.txt","r")
fileAsString = file.read()
arr = fileAsString.split('\n')
Expand All @@ -31,6 +57,11 @@ def CheckCredentials(username,password):
return False

def AddFolder(username):
"""Add folder for current user if necessary
Args:
username (str): The username to create image folder
"""
try:
newFolder = os.getcwd() + "/static/UserPictures/" + username
os.mkdir(newFolder)
Expand Down
5 changes: 5 additions & 0 deletions app/UserInfo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UserInfo Module
===============

.. automodule:: UserInfo
:members:
Binary file modified app/__pycache__/UserInfo.cpython-37.pyc
Binary file not shown.
Binary file added app/__pycache__/main.cpython-37.pyc
Binary file not shown.
53 changes: 53 additions & 0 deletions app/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'dogstagram'
copyright = '2019, Hirsh Guha, Jordan Love, Giang Nguyen, Ryan Pope, John Quitno'
author = 'Hirsh Guha, Jordan Love, Giang Nguyen, Ryan Pope, John Quitno'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
20 changes: 20 additions & 0 deletions app/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. dogstagram documentation master file, created by
sphinx-quickstart on Tue Apr 9 22:07:28 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to dogstagram's documentation!
======================================

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
49 changes: 47 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
app = Flask(__name__)
app.secret_key = os.urandom(24)


@app.route('/', methods=['GET'])
def main():
"""Loads basic frontward facing login page
Returns:
html: The rendered index.html template
"""
return render_template('index.html')


@app.route('/login', methods=['GET', 'POST'])
def login():
"""Logs a user in if valid login is provided
Returns:
html: The rendered index.html template
"""
if request.method == 'POST':
s = request.form.to_dict()['json_string']
json_acceptable_string = s.replace("'", "\"")
Expand All @@ -37,6 +48,11 @@ def login():

@app.route('/signup', methods=['GET', 'POST'])
def signup():
"""Creates a new user if the user signs up for Dogstagram
Returns:
html: The rendered index.html template
"""
s = request.form.to_dict()['json_string']
json_acceptable_string = s.replace("'", "\"")
d = json.loads(json_acceptable_string)
Expand All @@ -57,34 +73,50 @@ def signup():

@app.route('/landing')
def landing():
"""Loads landing page to see photos
Returns:
html: The landing.html template if logged in, login page otherwise
"""
if g.user:
return render_template('landing.html', user=g.user)
return redirect(url_for('login'))

@app.before_request
def before_request():
"""Assigns the username if the user is logged in
"""
g.user = None
if 'user' in session:
g.user = session['user']


@app.route('/dropsession')
def dropsession():
"""Remotes a user from session data (logging them out)
Returns:
redirect: Redirects logged out user to login page
"""
session.pop('user', None)
return redirect(url_for('login'))

@app.route('/upload', methods=["GET", "POST"])
def upload_page():
"""Uploads a posted image to the user's profile
Returns:
redirect: Redirects user to profile page regardless
"""
if not g.user:
return redirect(url_for('login'))
if request.method == "GET":
return render_template('upload.html')
return redirect(url_for('landing'))
elif request.method == "POST":
if 'image' not in request.files:
return redirect(url_for('landing'))
file = request.files['image']
if file.filename == '':
flash('No selected filename.')
return redirect(url_for('landing'))
if file:
AddFolder(g.user)
Expand All @@ -94,6 +126,14 @@ def upload_page():

@app.route('/user/<username>/images')
def getUserImages(username):
"""Gets all images that belong to a user
Args:
username (str): The username to use to find images
Returns:
str: JSON list of image URLs
"""
if not UserExists(username):
return "False"
elif not g.user:
Expand All @@ -104,6 +144,11 @@ def getUserImages(username):

@app.route('/user/images')
def getCurrentUserImages():
"""Gets all images that belong to current user
Returns:
str: JSON list of image URLs
"""
if not g.user:
return redirect(url_for('login'))
return getUserImages(g.user)
Expand Down
5 changes: 5 additions & 0 deletions app/main.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Web page routing module
=======================

.. automodule:: main
:members:
Binary file added app/static/.DS_Store
Binary file not shown.
Empty file.
46 changes: 12 additions & 34 deletions app/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var config = {
firebase.initializeApp(config);



/** Handles the login, checks the database/files to assure authentication, then pushes it to the backend */
function login() {
//set up document reference
var firestore = firebase.firestore();
Expand All @@ -25,41 +25,13 @@ function login() {
let userValid = false;
let passvalid = false;

/* currently broken
//query for matching username and password in Firebase
docRef.where("user", "==", userInput).get().then(function (doc) {
if (doc && doc.exists) {
let myData = doc.data();
console.log( myData );
if (myData.user == userInput) {
//userValid = true;
console.log( "myData.user: ");
}
if (myData.pass == passInput) {
//passValid = true;
console.log( "myData.pass: ");
}
}
})
console.log(password.value)
if ((password.value == "password") && (username.value == "username"))
{
window.location.href = "landing.html";
}
else
{
alert("The username or password you entered doesn't exist!");
}
*/
$.ajax({
type: "POST",
url: '/login',
data: {
json_string: JSON.stringify({username: username.value, password: password.value})
},
success: function(response){
console.log(response)
//goes to landing after login but will return to login if user does not exist
if(response=="False")
{
Expand All @@ -71,10 +43,10 @@ function login() {
}
}
})
console.log(password.value)
}


/** Stores the inputted username and password(if it doesn't exist already) in the file/database */

function signup()
{
Expand Down Expand Up @@ -121,8 +93,7 @@ function signup()
});
}



/** Useless function */
function addImage()
{
//set up document reference
Expand All @@ -145,21 +116,27 @@ function addImage()
});
}

/** Drops the session if confirmed */
function logOut()
{
window.location.href = '/dropsession';
if(confirm("are you sure you want to log out?"))
{
window.location.href = '/dropsession';
}
}

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

/** Opens the image uploader */
function uploadImage()
{
document.querySelector('#upload').style.visibility = "visible";
}

/** Gets the images from the backend */
function fetchImages()
{
$.ajax({
Expand Down Expand Up @@ -223,4 +200,5 @@ window.onload = () => {
}


}
}

Loading

0 comments on commit 0b529a0

Please sign in to comment.