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
- Python 3.5 - Flask framework, SQLAlchemy, OAuth2, Jsonify
- Other tools used while building:
- Install Python 3.5, and then
pip install
:flask
sqlalchemy
oauth2client
httplib2
- Setup Database:
- Skip this step and delete
restaurantmenuwithusers.db
file if you want to use my database setup - Run
database_setup.py
using Python to setup Database - Run
initiating_db_with_users.py
using Python to populate the database with values.- You can modify this file with your own values.
- Skip this step and delete
- 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. - 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 ownclient_secrets.json
file.
- A Mockup of the client secrets json file is already present with other credentials in it
- For Facebook - Goto Facebook's Developers webpage and create AppCredentials. Copy the App ID and App Secret into the
fb_client_secrets.json
file.
- For Google - Create App Credentials at Google's Developers webpage and download the clients secret JSON file into the project. Rename it to
- 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
-
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.
-
initiating_db_with_users.py
is used to populate the empty database which was created. -
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 andinitiating_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.
- Files
-
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.
- The HTML templates are located in templates folder.
- CSS style sheet
styles.css
is located in static folder
-
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.