A Python - Flask based web application with following features:
- Features
- Software Stack Used
- Initial Configuration of APP
- Deploy With Docker Compose
- Deploy using Docker, Standalone SQL DB
- Run Locally For Debugging
- Useful References
- Any Guest user can register for portal access using a form.
- Admin users can login to portal --> Approve / Reject access requests received + See details of all registered users.
- Once Approved, registered person will get credentials via registered email.
- Already registered users can request for credentials which will be delivered via registered email.
All credentials are by design, hashed and stored in database for enhanced security.
- My SQL database
- Python Flask -Web Application
- PHP MyAdmin [For easier management of sql database]
Please edit this properly before deployment, for app to work properly. The default values in
config.json
are set to match with config we have in docker-compose. Please ensure to do the matching changes inconfig.json
,docker-compose.yml
{
"MYSQL_HOST" : "host name / ip of sql database",
"MYSQL_USER" : "username to login to sql db",
"MYSQL_PASSWORD" : "password to login to sql db",
"MYSQL_DB" : "Target database name inside sql db",
"APP_SECRET" : "XXXXXXXXXXXXXX",
"RandomPassLength" : 10,
"App_Interface" : "127.0.0.1 | 0.0.0.0",
"MAIL_PASSWORD" : "xxxxxxx",
"MAIL_SERVER" : "smtp.gmail.com",
"MAIL_PORT" : 465,
"MAIL_USERNAME" : "xxxxxxxxxx@gmail.com"
}
- MYSQL_XXXXX : DATABASE related config.
- APP_SECRET : Used to hash the browser session cookies to avoid cookie tampering attack. Also same is used for Bcrypt Hashing the passwords stored in SQL DB.
- RandomPassLength : Once a developer is verified, will get a randomly generated password of length specified here
- MAIL_XXXX : Relavant email server config for sending mails to developers using Flask_MySQLdb package.
- Clone the repo using command -->
git clone https://github.com/adithyaamara/FlaskApp.git
- Change Current Working Directory to app using cmd -->
cd FlaskApp/
- Edit all configurable parameters of this application in
.env
(Otherwise defaults are applied, Some Features will not work).Due to a known issue, Please avoid editing
MYSQL_DB
variable in .env for the sql auto import to work. - Run whole application using
docker-compose up -d --build
- First Visit the url -->
http://docker-host-ip:8080
to use PhpMyAdmin and manage SQL Database.You should see that all the required databases and tables are auto imported to SQL DB from
FlaskAPP.sql
- PhpMyAdmin can also be used for any further Database related operations like adding / deleting admins etc...
It is Recommended to delete the default admin user, add your own admin user by inserting a record to
admins
table usingPHPMyAdmin
. While adding the admins manually, passwords must be hashed and stored in database. Hash Your password here - Visit the Flask application homepage at
http://docker-host-ip:[4444 | PORT YOU exposed IN docker-compose.yml]
and login with default userid(1234567890
) and password (admin
) OR using your own admin credentials if you have added any in previosu step.
- If a mysql db with above configuration specified in
config.json
is up and ready, Proceed as follows: FlaskApp.sql
has all the required SQL statements for creating and adding sample data to tables [Edit the data insert statements if needed]. Use any helper likephpmyadmin.co
to execute all the sql statements and setup the database.- Once database is ready with above config, one can proceed to run the application.
git clone https://github.com/adithyaamara/FlaskApp.git
- create a file named
config.json
as templated above sudo docker build -t flaskapp:v1.0 .
sudo docker run -d -p4444:4444 flaskapp:v1.0
- View HomePage / Site Map At :
http://docker-machine-ip:4444/
pip install virtualenv
virtualenv venv
- open command prompt and
cd venv
./Scripts/activate
(For Windows) |source venv/bin/activate
(For Linux/mac)git clone https://github.com/adithyaamara/FlaskApp.git
cd FlaskApp
- create and edit a file named
config.json
as templated above python main.py
- view homepage at http://127.0.0.1:4444/
- Deploy App to production :
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04