Code Monkey home page Code Monkey logo

ud330's Introduction

ud330

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 People

Contributors

adarsh0806 avatar asparr avatar cristianathompson avatar dalex01 avatar fluffybeing avatar jeffudacity avatar jon-engelbert avatar karlud avatar lobrown avatar mladenpn avatar pmallory avatar stevewooding avatar trevstoke avatar veronikabenkeser avatar walesmd avatar weehaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ud330's Issues

Image Upload

There is an error with the database layout. The actual layout should be something like this:

puppiesdb

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

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

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.

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>

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.

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.

server-side-flow

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...

Typo

response = make_response(json.dumps('Failed to revoke token for given user.', 400))

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)

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>

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.

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.

[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

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

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"

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

Add a README

Add content to the README to include details about this project.

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.