Skip to content

Commit 7e449c0

Browse files
api commit
1 parent 6681f14 commit 7e449c0

21 files changed

+522
-60
lines changed

.idea/OAuth2.0.iml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5:3e0ab3e6-b921-47c3-8dd8-0b40624f2bf1
1+
1.5:b9cb8e46-52f3-4a53-8670-fb7c998fd4ab
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1569168461
1+
1569480829
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1000
1+
0
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3e0ab3e6-b921-47c3-8dd8-0b40624f2bf1
1+
b9cb8e46-52f3-4a53-8670-fb7c998fd4ab
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c464abb2de7e4768b716e49fea041068
1+
8d957560a4e243bb8b81bf95ff1eea0c
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
-----BEGIN RSA PRIVATE KEY-----
2-
MIIEowIBAAKCAQEA4G8kTygGjeKsoNxbVOk4tSEg1CyVIz4ji09fRYan6EQ8PZ+S
3-
Wpytul6gWnw1ANzNwcbeSt2WnEdVr+NAfdrgemTzdrsgpg+nYydcm7+ux/yKDs47
4-
o3qSjioMrOo0t56bYEQPr7l2DLvjzIj4PrVPe2dC3DZSBdM/clxJ10rxXeSsh3Uy
5-
ojaXLmaVNheqGwlfij2EiVlvWLWeVAwJXitWwD+mIirmwk3e+bIGeRzaT8QlWYtP
6-
0clo5SU8OFw/zkFYaZ4xFfjsajWl6mYIX+ngHkzeGF4/RUGcvHaTj8iPS2+orkoI
7-
+pp5ArJcSjcA3QQuGrICi710w/z4P86/zPThXwIDAQABAoIBACepvKL4kd/1VUjA
8-
aKui49Cu4BxfHKQz0RhHmLCy0W2s0XCaiMTWt6UeH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EuJ1NlwjVrTfqCa2KbOV8CgYEA2cGi
16+
NawWJ330BfVUI+WQ3HWUPr5anxzkH0odDZs0PAk4fj9D6ZY2lREEyfaGwtJz3iq5
17+
XdPfarBcGClU7lFFo1oNrJ76dXMepXwxrhH7g6ZmsjxJoeh0uif2Gv7QrUpTpX0M
18+
uB4n4UtViCIQqIp5AloITpCJt+HWZC+JSTzlNcMCgYBT6g5jqGuGhi1U+Fcddz3Y
19+
X7NttJz1ISQeR8lW7YvaCm+XfoWG4vOuCFJaBzHgHi5Mnv9L7Vjr7a1fvTLkPJz3
20+
H5s1HWU+On2lI847z1/AQ+FEvgYPA9noBfVEfEF+brIbCZnxk6eaIxge6HRCeXKC
21+
t4SB0XkvxxrSetn8spOJSQKBgHsfwVgXtW8fCJtV2/1wEDiXQvs3JoZRD6uhfEv1
22+
NdO8YvT/UKcDCFnBBbQscIY3+Mvl3GnxIqJwlaITvLIDwhxbDuBMA9HlBa8MSgri
23+
oBQQQoEFFZ02ksmvTrh03AkfvawUyNxSMLpyniobGNAze7iYr5m8oCIYz+BWAIoo
24+
pHGBAoGBAK/1xMib2ohG0esly4zkYDJy78Sh9FrXoWMQ0zL0LdPZ4GACbFx/tYbF
25+
n3iV3xbcRTxhi/6rd7qKLjUnpCfAzLWOjUV8cyyFoAkJaB7W5KK7rVuO7WL5XCxc
26+
dqEo5/gP1Lq1Y4zLtRCk8hzkgk626e04BApN8UdBMhv88LCdC909
2727
-----END RSA PRIVATE KEY-----
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/home/basem/fullstack-nanodegree-vm/vagrant/OAuth2.0","disabled":false,"__vagrantfile":true}}}
1+
{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"C:/Users/Basem/code/oauth","disabled":false,"__vagrantfile":true}}}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/home/basem/fullstack-nanodegree-vm/vagrant/OAuth2.0
1+
C:/Users/Basem/code/oauth

api_server.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#THIS IS A WEBSERVER FOR DEMONSTRATING THE TYPES OF RESPONSES WE SEE FROM AN API ENDPOINT
2+
from flask import Flask
3+
app = Flask(__name__)
4+
5+
#GET REQUEST
6+
7+
@app.route('/readHello')
8+
def getRequestHello():
9+
return "Hi, I got your GET Request!"
10+
11+
#POST REQUEST
12+
@app.route('/createHello', methods = ['POST'])
13+
def postRequestHello():
14+
return "I see you sent a POST message :-)"
15+
#UPDATE REQUEST
16+
@app.route('/updateHello', methods = ['PUT'])
17+
def updateRequestHello():
18+
return "Sending Hello on an PUT request!"
19+
20+
#DELETE REQUEST
21+
@app.route('/deleteHello', methods = ['DELETE'])
22+
def deleteRequestHello():
23+
return "Deleting your hard drive.....haha just kidding! I received a DELETE request!"
24+
25+
if __name__ == '__main__':
26+
app.debug = True
27+
app.run(host='0.0.0.0', port=5000,threaded=False)

database_setup.pyc

479 Bytes
Binary file not shown.

fb_client_secrets.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"web": {
3+
"app_id": "564914114313490",
4+
"app_secret": "8fa09deac0f046f599a091c38016b5c6"
5+
}
6+
}

project.py

+53-22
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@
2727
APPLICATION_NAME = "Restaurant Menu Application"
2828

2929

30-
# Create anti-forgery state token
31-
@app.route('/login')
32-
def showLogin():
33-
state = ''.join(random.choice(string.ascii_uppercase + string.digits)
34-
for x in xrange(32))
35-
login_session['state'] = state
36-
# return "The current session state is %s" % login_session['state']
37-
return render_template('login.html', STATE=state)
38-
39-
4030
@app.route('/gconnect', methods=['POST'])
4131
def gconnect():
4232
# Validate state token
@@ -109,6 +99,11 @@ def gconnect():
10999
login_session['picture'] = data['picture']
110100
login_session['email'] = data['email']
111101

102+
user_id = getUserID(login_session['email'])
103+
if not user_id :
104+
user_id = createUser(login_session)
105+
login_session['user_id'] = user_id
106+
112107
output = ''
113108
output += '<h1>Welcome, '
114109
output += login_session['username']
@@ -122,6 +117,39 @@ def gconnect():
122117
return output
123118

124119

120+
# Create anti-forgery state token
121+
@app.route('/login')
122+
def showLogin():
123+
state = ''.join(random.choice(string.ascii_uppercase + string.digits)
124+
for x in xrange(32))
125+
login_session['state'] = state
126+
# return "The current session state is %s" % login_session['state']
127+
return render_template('login.html', STATE=state)
128+
129+
130+
131+
def createUser(login_session):
132+
newUser = User(name=login_session['username'], email=login_session[
133+
'email'], picture=login_session['picture'])
134+
session.add(newUser)
135+
session.commit()
136+
user = session.query(User).filter_by(email=login_session['email']).one()
137+
return user.id
138+
139+
140+
def getUserInfo(user_id):
141+
user = session.query(User).filter_by(id=user_id).one()
142+
return user
143+
144+
145+
def getUserID(email):
146+
try:
147+
user = session.query(User).filter_by(email=email).one()
148+
return user.id
149+
except:
150+
return None
151+
152+
125153
@app.route('/gdisconnect')
126154
def gdisconnect():
127155
access_token = login_session.get('access_token')
@@ -188,7 +216,7 @@ def showRestaurants():
188216
@app.route('/restaurant/new/', methods=['GET', 'POST'])
189217
def newRestaurant():
190218
if request.method == 'POST':
191-
newRestaurant = Restaurant(name=request.form['name'])
219+
newRestaurant = Restaurant(name=request.form['name'],user_id=login_session['user_id'])
192220
session.add(newRestaurant)
193221
flash('New Restaurant %s Successfully Created' % newRestaurant.name)
194222
session.commit()
@@ -236,7 +264,17 @@ def showMenu(restaurant_id):
236264
restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
237265
items = session.query(MenuItem).filter_by(
238266
restaurant_id=restaurant_id).all()
239-
return render_template('menu.html', items=items, restaurant=restaurant)
267+
268+
creator = getUserInfo(login_session['user_id'])
269+
270+
if creator.id == restaurant.user_id:
271+
# return True
272+
return render_template('menu.html', items=items, restaurant=restaurant, creator=creator)
273+
274+
creator = getUserInfo(restaurant.user_id)
275+
276+
return render_template('publicmenu.html', items=items, restaurant=restaurant, creator=creator)
277+
240278

241279

242280
# Create a new menu item
@@ -245,10 +283,10 @@ def newMenuItem(restaurant_id):
245283
restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
246284
if request.method == 'POST':
247285
newItem = MenuItem(name=request.form['name'], description=request.form[
248-
'description'], price=request.form['price'], course=request.form['course'], restaurant_id=restaurant_id)
286+
'description'], price=request.form['price'], course=request.form['course'], restaurant_id=restaurant_id,user_id=login_session['user_id'])
249287
session.add(newItem)
250288
session.commit()
251-
flash('New Menu %s Item Successfully Created' % (newItem.name))
289+
flash('New Menu %s Item Successfully Created' % newItem.name)
252290
return redirect(url_for('showMenu', restaurant_id=restaurant_id))
253291
else:
254292
return render_template('newmenuitem.html', restaurant_id=restaurant_id)
@@ -281,7 +319,6 @@ def editMenuItem(restaurant_id, menu_id):
281319
# Delete a menu item
282320
@app.route('/restaurant/<int:restaurant_id>/menu/<int:menu_id>/delete', methods=['GET', 'POST'])
283321
def deleteMenuItem(restaurant_id, menu_id):
284-
restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
285322
itemToDelete = session.query(MenuItem).filter_by(id=menu_id).one()
286323
if request.method == 'POST':
287324
session.delete(itemToDelete)
@@ -292,13 +329,7 @@ def deleteMenuItem(restaurant_id, menu_id):
292329
return render_template('deleteMenuItem.html', item=itemToDelete)
293330

294331

295-
def CreateUser(login_session):
296-
new_user = User(name=login_session['username'], email=login_session['email'], picture=login_session['picture'])
297-
session.add(new_user)
298-
session.commit()
299-
300-
301332
if __name__ == '__main__':
302333
app.secret_key = 'super_secret_key'
303334
app.debug = True
304-
app.run(host='0.0.0.0', port=5000)
335+
app.run(host='0.0.0.0', port=5000,threaded=False)

project.pyc

3.74 KB
Binary file not shown.

restaurantmenu.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)