This is a Flask web application for testing and demonstration purposes.
PYTHON/
├── app.py # Main Flask application entry point
├── requirements.txt # Python dependencies
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose configuration
├── entrypoint.sh # Container startup script
├── .dockerignore # Docker build exclusions
├── .env.example # Environment variables template
├── controllers/ # Controller classes
│ ├── base.py # Base controller with common functionality
│ ├── indexController.py
│ ├── form1Controller.py - form6Controller.py
│ ├── responseccController.py
│ ├── useraccountController.py
│ ├── resultsController.py
│ ├── employeeController.py
│ ├── salesController.py
│ └── ... (all other controllers)
├── templates/ # Jinja2 HTML templates
│ ├── base.html # Base layout template
│ ├── index.html
│ ├── form-1.html - form-6-celsius-fahrenheit.html
│ ├── inc/ # Include files (navigation, header, footer)
│ └── admin/ # Admin templates
├── api/ # REST API endpoints
│ └── routes.py # API Blueprint with /allusers and /user/<id>
├── data/ # SQLite database
│ └── Main.db # User database
├── scripts/ # Database utilities and scripts
└── static/ # Static files (CSS, JS, images)
-
Create a virtual environment (recommended):
python -m venv .venv .\.venv\Scripts\Activate.ps1 -
Install dependencies:
pip install -r requirements.txt
Quick Start (using startup scripts):
# PowerShell
.\start-server.ps1
# Command Prompt
start-server.batManual Start:
python app.pyThe application will be available at: http://localhost:5000/
You can configure the host and port using environment variables:
Environment Variables:
FLASK_HOST- Host to bind to (default:localhost- only accessible from local machine)FLASK_PORT- Port to listen on (default:5000)
Examples:
# Run on localhost only (default - more secure, not accessible from network)
$env:FLASK_HOST = "localhost"
python app.py
# Run on 127.0.0.1 (same as localhost)
$env:FLASK_HOST = "127.0.0.1"
python app.py
# Run on all interfaces (accessible from network)
$env:FLASK_HOST = "0.0.0.0"
python app.py
# Custom port
$env:FLASK_PORT = "8080"
python app.pyBatch (CMD):
set FLASK_HOST=localhost
set FLASK_PORT=8080
python app.pyYou can also modify the commented configuration section in start-server.ps1 or start-server.bat to set your preferred defaults.
The application can be run as a Docker container for isolated, reproducible deployments.
- Docker Desktop installed and running
- Docker Compose included with Docker Desktop
-
Build and start the container:
docker-compose upThis will:
- Build the Docker image
- Create and start the container
- Automatically initialize database tables (CREDENTIALS and EMPLOYEES)
- Start the Flask application on port 5000
-
Access the application:
- Open browser to
http://localhost:5000/
- Open browser to
-
Stop the container:
# Stop with Ctrl+C, then remove containers docker-compose down
Build the Docker image:
docker build -t flask-test-app .Run container manually (without docker-compose):
docker run -p 5000:5000 -v ${PWD}/data:/app/data flask-test-appRun in background (detached mode):
docker-compose up -dView logs:
docker-compose logs -fStop and remove containers:
docker-compose downRebuild after code changes:
docker-compose up --buildCreate a .env file from the example to customize settings:
Copy-Item .env.example .envEdit .env to configure:
FLASK_PORT- Port to expose (default: 5000)FLASK_DEBUG- Enable debug mode (default: True)SECRET_KEY- Session secret key (change for production!)
Example .env file:
FLASK_PORT=8080
FLASK_DEBUG=False
SECRET_KEY=your-super-secret-key-hereThe SQLite database is stored in the data/ directory, which is mounted as a Docker volume:
- Database file persists across container restarts
- To reset the database, stop the container and delete
data/Main.db - Database tables are automatically created on first run via
entrypoint.sh
- Automatic Database Initialization: Creates CREDENTIALS and EMPLOYEES tables on startup
- Sample Data: Populates employee directory with test data if empty
- Health Checks: Container monitors application health automatically
- Non-Root User: Runs as
flaskuserfor security - Volume Mounting: Database persists outside container
- Environment Variables: Configurable via
.envfile
Port conflict:
# Change port in docker-compose.yml or .env file
FLASK_PORT=8080
docker-compose upDatabase permission errors:
# On Windows, ensure the data directory exists
New-Item -ItemType Directory -Force -Path dataView container logs:
docker-compose logs flask-appReset everything:
docker-compose down -v # Remove volumes
Remove-Item data/Main.db # Delete database
docker-compose up --build # Rebuild and start freshAll pages are accessible via clean path-based URLs:
-
Home:
http://localhost:5000/ -
Forms:
- Form 1:
/form1- Information about yourself - Form 2:
/form2- Book Accommodation - Form 3:
/form3- Credit Card (with Luhn validation) - Form 4:
/form4- Login Form (credentials: admin/pw1234 or joe/doe) - Form 5:
/form5- Media Settings - Form 6:
/form6- Celsius/Fahrenheit Converter
- Form 1:
-
Pages:
- Orange Page:
/orangePage - Green Page:
/greenPage - Brown Page:
/brownPage - Child Window:
/childWindow - Nested Menu 1:
/nestedmenu1 - Nested Menu 2:
/nestedmenu2 - Overlay 1:
/overlay1 - Card Flip 1:
/cardflip1
- Orange Page:
-
Admin:
- Employee Finder:
/employee - Sales Statistics:
/sales
- Employee Finder:
- Get all users:
GET http://localhost:5000/api/allusers - Get user by ID:
GET http://localhost:5000/api/user/1
Credentials are stored in the database (data/Main.db in the CREDENTIALS table) with hashed passwords:
- Admin: username:
admin, password:pw1234 - Employee: username:
joe, password:doe
User Profile Management:
- Employee users have editable profile forms with data stored in the
USER_PROFILEStable - Profile data includes: title, initial, first name, middle name, last name, gender, and languages
- Profile changes are saved to the database and persist across sessions
- Click "Save" on the user account page to update profile information
- Logout: Visit
/logoutto end your session securely
Session-Based Authentication:
- User credentials verified against database with hashed passwords
- Session data stored securely server-side (not in cookies)
- Profile updates require active login session
- Unauthenticated access to
/useraccountredirects to login page - See SECURITY.md for detailed security documentation
Note: To reset or modify credentials, use the database utilities in utils/db_utils.py.
Test credit card numbers (valid per Luhn algorithm):
4111111111111111(Visa)5500000000000004(Mastercard)340000000000009(Amex)
- Flask 3.0.0 - Web framework
- Jinja2 3.1.2 - Template engine
- luhn 0.2.0 - Credit card validation
- SQLite - Database (embedded)
-
Create a new controller file in
controllers/directory:from controllers.base import BaseController class MycontrollerController(BaseController): def run(self): return self.render_view('my-template', self.data)
-
Create the corresponding template in
templates/directory -
Access at
http://localhost:5000/?action=mycontroller
Templates use Jinja2 syntax:
{% extends 'base.html' %}
{% block body %}
<div class="center">
<h2>My Page</h2>
<p>Content goes here</p>
</div>
{% endblock %}Make sure you're in the PYTHON directory when running:
cd PYTHON
python app.pyEnsure the data/Main.db file exists and is readable.
Change the port in app.py:
app.run(host='0.0.0.0', port=5001, debug=True)