Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f4d750b
Updated home page
Nov 13, 2017
15dbb64
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 13, 2017
ae19290
Login is smoother than ever
KaranErry Nov 13, 2017
87281cd
Login is smoother than ever
KaranErry Nov 13, 2017
ef90fdd
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 13, 2017
45264f6
some cleanup
KaranErry Nov 13, 2017
b10fd8b
added a connection to th db
jhonatancruz Nov 13, 2017
3a51693
added connection to db
jhonatancruz Nov 13, 2017
19fd4ac
fixing commit errors
KaranErry Nov 14, 2017
f3ec2c7
Added connection to db
jhonatancruz Nov 14, 2017
f6441ce
using theirs
KaranErry Nov 14, 2017
147eaca
added functionality for different positions such as student, professo…
jhonatancruz Nov 14, 2017
7d4ff69
app_insecure to app
jhonatancruz Nov 14, 2017
fe14bd5
added google's complete oauth example
KaranErry Nov 14, 2017
729b2a1
resolved merge conflict
KaranErry Nov 14, 2017
b9b4a8e
added student/deptHead/professor landing pages and more
jhonatancruz Nov 14, 2017
69b19f6
cleaned up debug stuff
KaranErry Nov 14, 2017
560947a
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 14, 2017
80c1345
app_insecure to app
KaranErry Nov 14, 2017
68f5736
added basic homepage text
KaranErry Nov 14, 2017
05a8cc7
Added DB hooks for the current student form
Nov 14, 2017
711d701
Actually saved the file
Nov 14, 2017
160a23c
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
Nov 14, 2017
ab9495f
Added display-tables functionality.
KaranErry Nov 14, 2017
082cc8d
jcruz local changes
jhonatancruz Nov 14, 2017
7c2aed0
Added display-tables functionality.
KaranErry Nov 14, 2017
38d5630
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 14, 2017
cebafb8
added markers
KaranErry Nov 14, 2017
9666393
added markers
KaranErry Nov 14, 2017
4a08c74
fixed merge conflicts, using mine
KaranErry Nov 14, 2017
7ad34fa
fixed merge conflicts, using mine
KaranErry Nov 14, 2017
dfca80b
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 14, 2017
7e1d0fb
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 14, 2017
235418a
Merge branch 'forms' of https://github.com/KaranErry/eForest into forms
KaranErry Nov 14, 2017
b78e487
LAST UPDATE BEFORE WE SWITCH DIRECTION :( Fixed insert queries.
KaranErry Nov 16, 2017
a60b26b
fixed merge conflicts used theirs
jhonatancruz Nov 21, 2017
e14d6f8
Updated form-submission pages, etc.
jhonatancruz Nov 21, 2017
caebbe3
Final version before Iteration 1 presentation
KaranErry Nov 21, 2017
9be8cab
Just Showing Duv
KaranErry Aug 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env/
.env
202 changes: 181 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import google_auth_oauthlib.flow
import google.oauth2.credentials
import oauth2client
from flask import Flask, render_template, session, redirect, request, url_for
from googleapiclient.discovery import build
import os
import google_auth_oauthlib.flow, google.oauth2.credentials, oauth2client
import requests

from flask import Flask, render_template, session, redirect, request, url_for
import psycopg2

app=Flask(__name__)
app.secret_key = 'Random value' #TODO: Replace this secret key with an actual secure secret key.

def after_request(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Expires"] = 0
response.headers["Pragma"] = "no-cache"
return response

@app.route('/')
def home():
return render_template('home.html')
Expand Down Expand Up @@ -43,27 +46,149 @@ def identity():
@app.route('/identity/login')
def login():
if 'credentials' not in session:
# No user session is active
return redirect(url_for('authorize'))
try:
# Load credentials from the session:
credentials = google.oauth2.credentials.Credentials(**session['credentials'])
# Build the service object for the Google OAuth v2 API:
oauth = build('oauth2', 'v2', credentials=credentials)
# Call methods on the service object to return a response with the user's info:
userinfo = oauth.userinfo().get().execute()
print(userinfo)
except google.auth.exceptions.RefreshError:
# Credentials are stale
return redirect(url_for('authorize'))

# Load credentials from the session:
credentials = google.oauth2.credentials.Credentials(**session['credentials'])
# Build the service object for the Google OAuth v2 API:
oauth = build('oauth2', 'v2', credentials=credentials)
# Call methods on the service object to return a response with the user's info:
userinfo = oauth.userinfo().get().execute()

# Verify whether the user signed in with a 'drew.ed' email address:
# Verify that the user signed in with a 'drew.ed' email address:
if 'hd' in userinfo: validDomain = userinfo['hd'] == 'drew.edu'
else: validDomain = False
if not validDomain:
print ("You signed in with a non-drew.edu a/c.")
return redirect(url_for('logout'))
return redirect(url_for('domainInvalid'))

conn = psycopg2.connect(database = "d2h7mc7fbep9fg", user = "ayqraqktgwqdwa", password = "2ae940eb19dca2ea77e40352d8a36ddaf964c9240053a5ea3252da2a63a35132", host = "ec2-54-163-255-181.compute-1.amazonaws.com", port = "5432")
cur = conn.cursor()

username = userinfo['email'][:userinfo['email'].index('@')]

print(username)

cur.execute("SELECT id FROM student_p WHERE id= (%s)", (username,))
entryStudent = cur.fetchone()
# print(entryStudent)
cur.execute("SELECT id FROM prof_m WHERE id= (%s)", (username,))
entryProf= cur.fetchone()

print(type(entryStudent), type(entryProf))

studentIn= False
professorIn= False

if entryStudent== None and entryProf== None:
return render_template("newUser.html", userinfo=userinfo)
else:
if entryStudent!=None:
if username in entryStudent:
studentIn= True
return render_template("landingStudent.html", userinfo=userinfo, studentIn=studentIn)
elif entryProf!=None:
if username in entryProf:
professorIn= True
return render_template("landingProf.html", userinfo=userinfo, professorIn=professorIn)
else:
return render_template("newUser.html", userinfo=userinfo)


@app.route('/landingHome', methods=["POST", "GET"])
def landingHome():
if request.method == "POST":
conn = psycopg2.connect(database = "d2h7mc7fbep9fg", user = "ayqraqktgwqdwa", password = "2ae940eb19dca2ea77e40352d8a36ddaf964c9240053a5ea3252da2a63a35132", host = "ec2-54-163-255-181.compute-1.amazonaws.com", port = "5432")
cur = conn.cursor()
studentIn= False
selectOption=request.form.get("select")
# Load credentials from the session:
credentials = google.oauth2.credentials.Credentials(**session['credentials'])
# Build the service object for the Google OAuth v2 API:
oauth = build('oauth2', 'v2', credentials=credentials)
# Call methods on the service object to return a response with the user's info:
userinfo = oauth.userinfo().get().execute()

# TODO: Store user's profile info in persistent storage.
if selectOption == "Student":
entries=cur.execute("INSERT INTO student_p (id, first_name, last_name, expected_grad) VALUES(%s, %s, %s, %s)", (userinfo['email'][:userinfo['email'].index('@')], userinfo['given_name'], userinfo['family_name'], None))
conn.commit()
conn.close()
return render_template("landingStudent.html", userinfo=userinfo, studentIn=studentIn)
elif selectOption =="DepartmentHead":
entries=cur.execute("INSERT INTO prof_m VALUES(%s,%s,%s,%s,%s)",(userinfo['email'][:userinfo['email'].index('@')], userinfo['given_name'], userinfo['family_name'],None, True))
conn.commit()
conn.close()
return render_template("landingDeptHead.html", userinfo=userinfo)
elif selectOption =="Professor":
print("got to 125")
entries=cur.execute("INSERT INTO prof_m VALUES(%s,%s,%s,%s,%s)",(userinfo['email'][:userinfo['email'].index('@')], userinfo['given_name'], userinfo['family_name'], None, False))
conn.commit()
conn.close()
return render_template("landingProf.html", userinfo=userinfo)

return "Hello, " + userinfo['name'] + "!"
@app.route('/landingStudent', methods=["POST","GET"])
def landingStudent():
if request.method == "POST":
student = {}
student['majors']=request.form.get("studentMajor")
student['minors']= request.form.get("studentMinor")
student['programs']= request.form.get("studentProgram")
# Load credentials from the session:
credentials = google.oauth2.credentials.Credentials(**session['credentials'])
# Build the service object for the Google OAuth v2 API:
oauth = build('oauth2', 'v2', credentials=credentials)
# Call methods on the service object to return a response with the user's info:
userinfo = oauth.userinfo().get().execute()

conn = psycopg2.connect(database = "d2h7mc7fbep9fg", user = "ayqraqktgwqdwa", password = "2ae940eb19dca2ea77e40352d8a36ddaf964c9240053a5ea3252da2a63a35132", host = "ec2-54-163-255-181.compute-1.amazonaws.com", port = "5432")
cur = conn.cursor()

# Get the program IDs
# TODO handle potential of different programs w/ same name
id_select = "SELECT id FROM program_m WHERE name = %s"
cur.execute( id_select, [student['majors']] )
student['majors'] = cur.fetchone()
cur.execute( id_select, [student['minors']] )
student['minors'] = cur.fetchone()
cur.execute( id_select, [student['programs']] )
student['programs'] = cur.fetchone()

# Insert the info
prog_insert = "INSERT INTO program_members_m VALUES (%s,%s)"
studentid = userinfo['email'][:userinfo['email'].index('@')]

cur.execute(prog_insert, (student['majors'], studentid))
cur.execute(prog_insert, (student['minors'], studentid))
cur.execute(prog_insert, (student['programs'], studentid))
# TODO handle multiple of each field except studentGradYear && posibiltiy of not having any && the possibility of duplicate submission attempts

print( student['majors'], student['minors'])

# TEST
cur.execute("SELECT * FROM student_p")
print(type(cur.fetchall()))


# Commit & close DB connection
cur.close()
conn.commit()
conn.close()
studentIn= True

return render_template("landingStudent.html", userinfo=userinfo, studentIn=studentIn)

@app.route('/landingProf', methods=["POST","GET"])
def landingProf():
return render_template("landingProf.html")

@app.route('/landingDeptHead', methods=["POST","GET"])
def landingDeptHead():
return render_template("landingDeptHead.html")

# Log user out of app by revoking auth credentials
@app.route('/identity/logout')
def logout():
if 'credentials' in session:
Expand All @@ -76,7 +201,38 @@ def logout():
# Delete the credentials from the session cookie:
del session['credentials']

return redirect(url_for('identity'))
if 'doNext' in request.args and request.args['doNext'] == 'login':
return redirect(url_for('login'))
else:
return render_template('logoutSuccess.html')

@app.route('/search', methods=["POST","GET"])
def search():
# Load credentials from the session:
credentials = google.oauth2.credentials.Credentials(**session['credentials'])
# Build the service object for the Google OAuth v2 API:
oauth = build('oauth2', 'v2', credentials=credentials)
# Call methods on the service object to return a response with the user's info:
userinfo = oauth.userinfo().get().execute()

conn = psycopg2.connect(database = "d2h7mc7fbep9fg", user = "ayqraqktgwqdwa", password = "2ae940eb19dca2ea77e40352d8a36ddaf964c9240053a5ea3252da2a63a35132", host = "ec2-54-163-255-181.compute-1.amazonaws.com", port = "5432")
cur = conn.cursor()

cur.execute("SELECT * FROM program_members_m")
program_members_ENTIRE = cur.fetchall()
cur.execute("SELECT * FROM program_m")
program_ENTIRE = cur.fetchall()
cur.execute("SELECT * FROM student_p")
student_ENTIRE = cur.fetchall()
cur.execute("SELECT * FROM prof_m")
prof_ENTIRE = cur.fetchall()
return render_template("search.html", program_members=program_members_ENTIRE, program=program_ENTIRE, student=student_ENTIRE, prof=prof_ENTIRE)

# def showStudents():
# return render_template()
#
# def showProfs():
# return render_template()

# Authorize using OAuth
@app.route('/identity/login/authorize')
Expand Down Expand Up @@ -123,11 +279,15 @@ def oauth2callback():
flow.fetch_token(authorization_response = authorization_response)

# Store credentials in the session:
# TODO: When migrating to production, store these credentials in a persistent database instead.
session['credentials'] = credentials_to_dict(flow.credentials)

return redirect(url_for('login'))

# Display invalid-sign-in page and prompt for re-login:
@app.route('/identity/domainInvalid')
def domainInvalid():
return render_template('domainInvalid.html')


# HELPER FUNCTIONS

Expand Down
Loading