This repository contains the code used in the Udacity course Full-Stack Foundations. This code is intended to be a supplement to the course material and runs in the vagrant environment provided in the course. Please report any errors in the code or feel free to make a pull request and I will get to the issue as soon as possible.
ud330's Introduction
ud330's People
Forkers
adarsh0806 jon-engelbert mladenpn flaresight hahnsangkim axs8265 linusdong agratson15 trevstoke kristofereng jmonkg smandekar1 wlsankey mslef vunne lukedonley luhar88 acabra85 archan93 arslanrafique ptaferner onlyjsmith macmania ruchithak codepileman climboid sus193 craigmulligan skh asparr jeffudacity bahobab vmtrooper iuliiakot sandyarathi thinksource alexcleu g3p zacariasbendeck vokidah vicpanizza talib570 markdonofrio zlw241 dalex01 unjo63 alishakiba abhigoud2212 dougbrunson mwhitmore1 joeykou tsubasak111 manjushabolishetty moscowjh izogain pzawadzk ntromboukis buckocee chris-w-jarvis clifntx neuwenwolf teodormavrodiev ba7ou skmezanul michaelmissouri hrshtvaish743 mic0331 nojno rickeshd seyfig wuhao007 guilhermecoelho erfan00 ai-made-simple adalee2future jnajem-1 skepticaldev tomrhoads guysk wkschnoor ikanez avastamin overmellow cfsu nellmartinez sara2592 saraducks guillaumesimler vinodhthiagarajan1309 cardvark bestran j2ws sandeshpp abdullah1111 sunburst15 bjellesma dominiquetheodore kapa93 tahmidul12 rt-tlud330's Issues
Typo
ud330/Lesson2/step6/project.py
Line 152 in fc0cf20
The parenthesis should end before the coma, not after the 400:
Error:
response = make_response(json.dumps('Failed to revoke token for given user.', 400))
Fix:
response = make_response(json.dumps('Failed to revoke token for given user.'), 400)
login button still visible after sign in due to error in login.html page script line 40
https://github.com/udacity/ud330/blob/master/Lesson4/step2/templates/login.html#L40
Change this line
$('#signinButton').attr('style', 'display: none');
to this one
$('#signInButton').attr('style', 'display: none');
gdisconnect file produced error, KeyError: 'access_token'
code copied as is produced the error
I resolved it by changing the first line from :
access_token = login_session['access_token']
to
access_token = login_session.get('access_token')
login.html script for ajax should be updated
Hello!
So in my editor, while writing the signinCallback function, I got an error saying "$ not defined" meaning that the jquery script is not connecting to the file. Upon inspecting the link, I get a "your file is not found message. Upon inspecting chrome developer tools with login.html, there is an error with the script saying "Failed to load resource: net::ERR_FILE_NOT_FOUND". I'll do a pull request for updating the script link!
Lesson 4 Step 2 project.py
Add a README
Add content to the README to include details about this project.
Lesson 6: Creating Google Sign In (Migrate from Google+ Sign-In)
Please Migrate Lesson 6 from Google+ Sign-In
The Google+ Sign-in feature has been fully deprecated as of March 7, 2019.
Developers should migrate to the more comprehensive Google Sign-in authentication system.
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
}
</script>
</body>
</html>
Cancel button does not work
In the examples for editing a restaurant and a menu item, the cancel button does not work. As pointed out by a fellow classmate, the solution is to add type="button" within for the cancel button.
Udacity discussion forum post here:
https://discussions.udacity.com/t/delete-restaurant-or-delete-menuitem/20566/2
oauth2client.client.OAuth2Credentials object is not JSON serializable
In lesson 2, step 5:
After I accept the terms for the application to connect to my g+ account, I get the following error in the terminal. The browser does not redirect. I have also tried to run the same test with code supplied here on github, even from future steps in this lesson.
#!python
cristian step7 python project.py
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
*127.0.0.1 - - [22/Apr/2015 22:37:56] "GET /login HTTP/1.1" 200 -
*done!
*127.0.0.1 - - [22/Apr/2015 22:38:00] "POST /gconnect? *state=LEMD4F2L1QNR0KKJMRI51KWWM4HHHQTH HTTP/1.1" 500 -
*Traceback (most recent call last):
* File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
* return self.wsgi_app(environ, start_response)
*File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
* response = self.make_response(self.handle_exception(e))
*File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1479, in full_dispatch_request
response = self.process_response(response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1693, in process_response
self.save_session(ctx.session, response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 837, in save_session
return self.session_interface.save_session(self, session, response)
File "/usr/local/lib/python2.7/dist-packages/flask/sessions.py", line 326, in save_session
val = self.get_signing_serializer(app).dumps(dict(session))
File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 565, in dumps
payload = want_bytes(self.dump_payload(obj))
File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 847, in dump_payload
json = super(URLSafeSerializerMixin, self).dump_payload(obj)
File "/usr/local/lib/python2.7/dist-packages/itsdangerous.py", line 550, in dump_payload
return want_bytes(self.serializer.dumps(obj))
File "/usr/local/lib/python2.7/dist-packages/flask/sessions.py", line 85, in dumps
return json.dumps(_tag(value), separators=(',', ':'))
File "/usr/local/lib/python2.7/dist-packages/flask/json.py", line 126, in dumps
rv = _json.dumps(obj, **kwargs)
File "/usr/lib/python2.7/json/__init__.py", line 250, in dumps
sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
chunks = list(chunks)
File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
for chunk in _iterencode_dict(o, _current_indent_level):
File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 442, in _iterencode
o = _default(o)
File "/usr/local/lib/python2.7/dist-packages/flask/json.py", line 83, in default
return _json.JSONEncoder.default(self, o)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <oauth2client.client.OAuth2Credentials object at 0x7fca10795b10> is not JSON serializable
CSS and HTML Missing in "Creating Google Sign In"
Image Upload
Outdated code in login.html - Documentation for Solution!
For those of you who are here in hopes of getting some clarity on the outdated solution in step 5 of Lesson 6: Create Google Sign in here is some helpful documentation that shows more up to date implementation of what is needed in the login.html file.
Following through step 6 should provide insight into what is new to the Google OAuth2 functionality. Step 7 would replace what is already provided as a solution in the project.py file for the /gconnect endpoint, if that is something of interest.
Hopefully Udacity can make updates to this repo and the course videos soon...
[FIX] here's my fix to fbconnect() in Graph API v3.2
fbconnect()
in project.py
isn't working as it is using v3.2 Graph API. Here's my solution that even doesn't requires local fb_client_secrets.json
anymore:
@app.route('/fbconnect', methods=['POST'])
def fbconnect():
if request.args.get('state') != login_session['state']:
response = make_response(json.dumps('Invalid state parameter.'), 401)
response.headers['Content-Type'] = 'application/json'
return response
access_token = request.data
print "access token received %s " % access_token
# Use token to get user info from API
userinfo_url = "https://graph.facebook.com/me"
url = '%s?access_token=%s&fields=name,id,email,picture' % (userinfo_url, access_token)
h = httplib2.Http()
result = h.request(url, 'GET')[1]
# print "url sent for API access:%s"% url
# print "API JSON result: %s" % result
data = json.loads(result)
login_session['provider'] = 'facebook'
login_session['username'] = data["name"]
login_session['email'] = data["email"]
login_session['facebook_id'] = data["id"]
# The token must be stored in the login_session in order to properly logout
login_session['access_token'] = access_token
# Get user picture
login_session['picture'] = data["picture"]["data"]["url"]
# see if user exists
user_id = getUserID(login_session['email'])
if not user_id:
user_id = createUser(login_session)
login_session['user_id'] = user_id
output = ''
output += '<h1>Welcome, '
output += login_session['username']
output += '!</h1>'
output += '<img src="'
output += login_session['picture']
output += ' " style = "width: 300px; height: 300px;border-radius: 150px;-webkit-border-radius: 150px;-moz-border-radius: 150px;"> '
flash("Now logged in as %s" % login_session['username'])
return output
implementing login features other than OAuth
Hi Lorenzo,
just wondering, quick query/question ?
I learned a lot with this course and wondering how can I implement login/registration feature other than OAuth and what would be the best package that I can use. please suggest
problem statement/features I am trying to implement in my web app
user can register in site (if your don't has his/her social login like google, facebook, msn, etc...)
Roles implementation, so that content can be managed based on Roles/admin console/dashboard
which package should I use/you guys suggest
-- Flask-Login ?
-- Flask-Security ?
-- Flask-Admin ?
Appreciate it.
project.py URLs
I believe the 'https://www.googleapis.com/oauth2/v1/...' urls are out of date.
Such as userinfo and tokeninfo
Google API expired on March 7, 2019 (today)
lesson 2 step 3
Google+ sign in is deprecated, so lesson 2 step 3 (login.html file) should look like this for any button to appear
<script src="https://apis.google.com/js/platform.js" async defer></script>ud330/Lesson2/step5/project.py Google Log In doesn't work
Hi,
After updating the client id and client_secrets.json I've found that the Google sign in still doesn't work.
I've seen other issues suggesting fixes to this but no one from Udacity seems to have responded to any of them.
The issue that I'm experiencing is that once the Sign in button is clicked and the google acount is chosen from the pop-up window, the window closes and nothing else happens. It seems to me that the signInCallback function in login.html is not actually being called.
newMenuItem method indentation error on project.py
Starting from lesson3 step 3 there is an indentation error on newMenuItem method on project.py file. That prevents logged in users from adding new item even if they are the creator of the restaurant.
For Lesson 3 Step 3: between lines 298 and 304
For Lesson 4 Step 1: between lines 297 and 303
For Lesson 4 Step 2: between lines 364 and 370
FB Login button broken in FireFox 56.0
The <fb:login-button>
doesn't need to be wrapped in a <button>
as it is in this file. On FireFox 56.0 it make the button unusable (the sendTokenToServer()
function is never called). It took sereral hours of head scratching to figure out why it wasn't all working together. Please spare others this headache.
Unicode
Missing return
I might be missing something since I am still learning, but when checking for an error in the access token info the response is not returned after line 73.
file "ud330/Lesson2/step6/project.py", /gconnect method need to update login_session['access token'] after line 90: "if stored_access_token is not None and gplus_id == stored_gplus_id:"
in file "ud330/Lesson2/step6/project.py"
/gconnect method
need to update login_session['access token'] after
line 90: "if stored_access_token is not None and gplus_id == stored_gplus_id:
"
It is better to add this: login_session['access_token'] = credentials.access_token
without this line of code, when you login again, the new access token will not be registered in session, the expired one is still in session
fbdisconnect is not working
fbdisconnect is not working
fbdisconnect function not working.
Is my understanding that some code is missing, see below:
Githbub Link:
https://github.com/udacity/ud330/blob/master/Lesson4/step2/project.py
Code:
@app.route('/fbdisconnect')
def fbdisconnect():
facebook_id = login_session['facebook_id']
# The access token must me included to successfully logout
access_token = login_session['access_token']
url = 'https://graph.facebook.com/%s/permissions?access_token=%s' % (facebook_id,access_token)
h = httplib2.Http()
result = h.request(url, 'DELETE')[1]
return "you have been logged out"
Correct code that worked for me:
@app.route('/fbdisconnect')
def fbdisconnect():
facebook_id = login_session['facebook_id']
# The access token must me included to successfully logout
access_token = login_session['access_token']
url = 'https://graph.facebook.com/%s/permissions?access_token=%s' % (facebook_id,access_token)
h = httplib2.Http()
result = h.request(url, 'DELETE')[1]
del login_session['username']
del login_session['email']
del login_session['picture']
del login_session['user_id']
del login_session['facebook_id']
return "you have been logged out"
lotsofmenu.py give error while running
error while running at line 26
Lesson2/step5/project.py - Why we need to verify access_token, user_id, CLIENT_ID after exchanging credentials?
From line 64 to line 90 in this file , I don't understand why it is necessary. I tried to comment this block (except line 77) and it still worked well. I followed Lorenzo's explanation very carefully but still didn't understand why.
As far as I know, after making step2_exchange
, we got a Credential from Google. Inside this Credential, we got a access_token
, and we can use this access_token
to request user info. I means that is enough, Google had provided us Credential, and we had gotten everything we need. But the next lines of code was really hard to comprehend to me!
# Check that the access token is valid.
access_token = credentials.access_token
url = ('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s'
% access_token)
h = httplib2.Http()
result = json.loads(h.request(url, 'GET')[1])
# If there was an error in the access token info, abort.
if result.get('error') is not None:
response = make_response(json.dumps(result.get('error')), 500)
response.headers['Content-Type'] = 'application/json'
return response
# Verify that the access token is used for the intended user.
gplus_id = credentials.id_token['sub']
if result['user_id'] != gplus_id:
response = make_response(
json.dumps("Token's user ID doesn't match given user ID."), 401)
response.headers['Content-Type'] = 'application/json'
return response
# Verify that the access token is valid for this app.
if result['issued_to'] != CLIENT_ID:
response = make_response(
json.dumps("Token's client ID does not match app's."), 401)
print "Token's client ID does not match app's."
response.headers['Content-Type'] = 'application/json'
return response
Key Error issue
These two lines in the disconnect() method in Lesson 4 Step 2:
del login_session['gplus_id']
del login_session['credentials']
Need to be deleted or logging out will cause a Key Error.
Thanks
-Mike
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.