Skip to content

Implementation of HTTP Web server with database using Python, SQLAlchemy and OAuth2

Notifications You must be signed in to change notification settings

bethirahul/Restaurant-Web-app

Repository files navigation

My Restaurants' Catalogue (App)

This is a Restaurants Catalogue app, built by Rahul Bethi.

It is a Web server with a database to store and edit information about Restaurants and the food items sold in them. It also has a user system with Google and Facebook OAuth 2.0 authentication to login and make modifications (CRUD operations) to add, edit or delete restaurants and their items.

It also has a JSON endpoint to provide restaurant details and item details

Built using

  • Python 3.5 - Flask framework, SQLAlchemy, OAuth2, Jsonify
  • Other tools used while building:
    • Vagrant - Ubuntu Linux - virtual machine
    • Postman
    • HTML, CSS
    • Google, Facebook OAuth 2.0 user login systems

Instructions to run

  1. Install Python 3.5, and then pip install:
    • flask
    • sqlalchemy
    • oauth2client
    • httplib2
  2. Setup Database:
  3. Run flask_app.py using Python, the app will be up and running on localhost:8000 address. Press Ctrl+C a few times to stop the server.
  4. To be able to use Google and Facebook OAuth 2.0 Authentication, App ID and Client Secret are needed from each of the providers.
    • For Google - Create App Credentials at Google's Developers webpage and download the clients secret JSON file into the project. Rename it to client_secrets.json.
      • A Mockup of the client secrets json file is already present with other credentials in it client_secrets.json. GO through it to setup credentials at google and replace it with your own client_secrets.json file.
    • For Facebook - Goto Facebook's Developers webpage and create AppCredentials. Copy the App ID and App Secret into the fb_client_secrets.json file.
  5. There are two type of JSON endpoints for restaurants.
    • /restaurants/json - for all restaurnts' name, ID and creater ID
    • /restaurants/<Restaurant ID>/json - for each restaruant's items

Design

  1. database_setup.py uses SQLAlchemy library to setup database and tables inside it.

    • It has classes for tables and Columns in each table.
    • Serialize function in each class to return items in easily readable format - to convert to json.
    • Menu Item class also has time variable which stores the time when the item is created. This is used to sort the latest added items.
  2. initiating_db_with_users.py is used to populate the empty database which was created.

  3. The server code flask_app.py is the main program.

    • It handles all the requests from the client, including Google and Facebook OAuth 2.0 Authentication.

      • Files client_secret.json for Google and initiating_db_with_users.py for Facebook are used get the App ID and Client Secret for respective providers.
      • A Random string is generated and used to send and receive as state_token to avoid Cross-site Reference Forgery attacks.
      • When a user log-in for the first time, A new entry is created in the database by getting the details of user's name, profile picture, email and ID.
      • A returning user is identified using his email address.
    • It also handles CRUD operations (using SQLAlchemy) on the database which we created, based on the requests we get from client.

    • Two Methods are supported, GET and POST as HTML5 only supports these two.

      • All links are accessed through GET method, only CRUD operations and login pages use POST method to submit the requests.
    • Flask framework is used to handle requests, send Flash messages for errors, and render Dynamic HTML webpages.

    • And at last the web server is run on localhost:8000 address.

Please read through the detailed code comments in flask_app.py to know how the app is built.

Screenshots of all the pages are located in Screenshots folder.

My LinkedIn profile

https://www.linkedin.com/in/rahulbethi

About

Implementation of HTTP Web server with database using Python, SQLAlchemy and OAuth2

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published