Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hguha/Dogstagram
Browse files Browse the repository at this point in the history
  • Loading branch information
giangpro93 committed Apr 10, 2019
2 parents f7afd7c + defec58 commit bb0170e
Show file tree
Hide file tree
Showing 43 changed files with 15,131 additions and 25 deletions.
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')
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 g.user:
return redirect(url_for('login'))

Expand All @@ -102,6 +142,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:
23 changes: 0 additions & 23 deletions app/templates/upload.html

This file was deleted.

Binary file added docs/Class Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions pydocs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4 changes: 4 additions & 0 deletions pydocs/_build/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 3bde46ff092fbb66f1fd51599bfc2d15
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added pydocs/_build/.doctrees/UserInfo.doctree
Binary file not shown.
Binary file added pydocs/_build/.doctrees/environment.pickle
Binary file not shown.
Binary file added pydocs/_build/.doctrees/index.doctree
Binary file not shown.
Binary file added pydocs/_build/.doctrees/main.doctree
Binary file not shown.
Loading

0 comments on commit bb0170e

Please sign in to comment.