Python Secure App is a web application built using Flask, SQLAlchemy, and Flask-Login. It provides user authentication and role-based access control using AWS Cognito. The app allows users to register, log in, and access different routes based on their roles (admin or reader). Admin users can view, edit, and delete user details.
This project can be used as a boilerplate for building secure web applications with user authentication and role-based access control.
- Python 3.8 or higher
- Virtual environment (optional but recommended)
-
Clone the repository:
git clone https://github.com/yourusername/python-secure-app.git cd python-secure-app -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile in the root directory and add the following variables:SECRET_KEY=your_secret_key SQLALCHEMY_DATABASE_URI=sqlite:///site.db
-
Initialize the database:
python create_db.py python create_roles.py
-
Create an admin user:
python create_admin.py
-
Run the Flask app:
python app.py
-
Access the app in your browser: Open your browser and go to
http://127.0.0.1:5000
/or/home: Home page accessible to all users./register: Registration page for new users./login: Login page for existing users./logout: Logout route to log out the current user./profile: Profile page accessible to logged-in users./admin: Admin dashboard accessible only to admin users./admin/users: List of all users accessible only to admin users./admin/users/<int:user_id>/edit: Edit user details accessible only to admin users./admin/users/<int:user_id>/delete: Delete user accessible only to admin users.
- Role-Based Access Control: The app uses role-based access control to restrict access to certain routes based on the user's role (
adminorreader). - Password Hashing: User passwords are hashed using
bcryptfor security. - CSRF Protection: The app uses
Flask-WTFfor form handling and CSRF protection.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or issues, please contact connect@rajeshscribe.com.