### Clone and Setup Enferno Repository (Bash) Source: https://github.com/level09/enferno/blob/master/docs/getting-started.mdx Clones the Enferno Git repository from GitHub, navigates into the project directory, and executes the setup script to create the virtual environment and install dependencies. ```bash git clone git@github.com:level09/enferno.git cd enferno ./setup.sh # Creates Python environment, installs requirements, and generates secure .env ``` -------------------------------- ### Install uv Package Installer (Bash) Source: https://github.com/level09/enferno/blob/master/docs/getting-started.mdx Installs the `uv` package installer using either pip or a direct curl script. `uv` is used for fast Python package management. ```bash pip install uv # Or using the installer script curl -sSf https://astral.sh/uv/install.sh | bash ``` -------------------------------- ### Run Enferno CLI Setup - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Initiates the interactive setup process for the Enferno CLI tool, guiding the user through server configuration and deployment options. ```bash enferno setup ``` -------------------------------- ### Enferno Environment Configuration (.env) Source: https://github.com/level09/enferno/blob/master/docs/getting-started.mdx Example environment variables used to configure the Enferno application, including Flask settings, database connection strings, and Redis URLs for caching, sessions, and Celery. ```bash # Core FLASK_APP=run.py FLASK_DEBUG=1 # 0 in production SECRET_KEY=your_secret_key # Database SQLALCHEMY_DATABASE_URI=sqlite:///enferno.sqlite3 # Or: postgresql://username:password@localhost/dbname # Redis & Celery REDIS_URL=redis://localhost:6379/0 CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/2 ``` -------------------------------- ### Run Docker Setup Source: https://github.com/level09/enferno/blob/master/README.md Single command to build and start the Enferno application and its dependencies using Docker Compose. ```Bash docker compose up --build ``` -------------------------------- ### Clone and Setup Application - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Clones the Enferno application repository, navigates into the directory, and runs the setup script to create a Python virtual environment, install requirements, and generate a secure .env file. ```bash git clone https://github.com/level09/enferno.git cd enferno ./setup.sh ``` -------------------------------- ### Start Enferno with Docker Compose (Bash) Source: https://github.com/level09/enferno/blob/master/docs/getting-started.mdx Builds and starts the Enferno application and its dependencies (Redis, PostgreSQL, Nginx, Celery) using Docker Compose with a single command. ```bash docker compose up --build ``` -------------------------------- ### Initialize Enferno Application (Bash) Source: https://github.com/level09/enferno/blob/master/docs/getting-started.mdx Activates the Python virtual environment, runs Flask commands to set up the database, create an initial admin user, and starts the Flask development server for local testing. ```bash source .venv/bin/activate # Activate environment flask create-db # Setup database flask install # Create admin user flask run # Start development server ``` -------------------------------- ### Clone and Setup Enferno Source: https://github.com/level09/enferno/blob/master/README.md Commands to clone the Enferno repository from GitHub, change into the project directory, and run the setup script. ```Bash git clone git@github.com:level09/enferno.git cd enferno ./setup.sh # Creates Python environment, installs requirements, and generates secure .env ``` -------------------------------- ### Install uv Package Installer - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Installs the fast Python package installer 'uv' using pip, recommended for setting up the Python environment. ```bash pip install uv ``` -------------------------------- ### Enable and Start Enferno Systemd Service - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Enables the Enferno Systemd service to start automatically on boot and immediately starts the service. ```bash sudo systemctl enable enferno sudo systemctl start enferno ``` -------------------------------- ### Install uv with pip Source: https://github.com/level09/enferno/blob/master/README.md Command to install the uv package installer using pip, a common method for Python package management. ```Bash pip install uv ``` -------------------------------- ### Install uv with curl script Source: https://github.com/level09/enferno/blob/master/README.md Alternative command to install the uv package installer using a curl script provided by astral.sh. ```Bash curl -sSf https://astral.sh/uv/install.sh | bash ``` -------------------------------- ### Run Flask Development Server Source: https://github.com/level09/enferno/blob/master/README.md Command to start the Flask development server, making the application accessible locally. ```Bash flask run ``` -------------------------------- ### Enable and Start Celery Worker Systemd Service - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Enables the Enferno Celery worker Systemd service to start automatically on boot and immediately starts the service. ```bash sudo systemctl enable enferno-celery sudo systemctl start enferno-celery ``` -------------------------------- ### Install Certbot and Nginx Plugin - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Installs the Certbot tool and its Nginx plugin, used for automatically obtaining and managing SSL certificates from Let's Encrypt. ```bash sudo apt install -y certbot python3-certbot-nginx ``` -------------------------------- ### Install PostgreSQL Database - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Installs the PostgreSQL database server and its contrib modules on the Ubuntu server. ```bash sudo apt install -y postgresql postgresql-contrib ``` -------------------------------- ### Running Flask Development Server (Bash) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This command starts the Flask development server for the Enferno project. It allows local testing and development of the application. Ensure the Flask environment is correctly set up. ```bash flask run ``` -------------------------------- ### Install Enferno CLI Tool - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Installs the Enferno command-line interface tool using pip, which is used for automated deployments on Ubuntu servers. ```bash pip install enferno_cli ``` -------------------------------- ### Configure OAuth in .env Source: https://github.com/level09/enferno/blob/master/README.md Example environment variables to enable and configure Google and GitHub OAuth integration for social login in the Enferno application. ```Bash # Google OAuth GOOGLE_AUTH_ENABLED=true GOOGLE_OAUTH_CLIENT_ID=your_client_id GOOGLE_OAUTH_CLIENT_SECRET=your_client_secret # GitHub OAuth GITHUB_AUTH_ENABLED=true GITHUB_OAUTH_CLIENT_ID=your_client_id GITHUB_OAUTH_CLIENT_SECRET=your_client_secret ``` -------------------------------- ### Install Core Dependencies - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Installs essential packages required for the traditional deployment, including Python 3 pip, venv, Nginx web server, and Redis server. ```bash sudo apt install -y python3-pip python3-venv nginx redis-server ``` -------------------------------- ### Activate Python Environment Source: https://github.com/level09/enferno/blob/master/README.md Command to activate the Python virtual environment created by the setup script, making project dependencies available. ```Bash source .venv/bin/activate ``` -------------------------------- ### Key Environment Variables (.env) Source: https://github.com/level09/enferno/blob/master/README.md Example of key environment variables used for configuring core settings, database, Redis/Celery, email, OAuth, and security in the Enferno application. ```Bash # Core FLASK_APP=run.py FLASK_DEBUG=1 # 0 in production SECRET_KEY=your_secret_key # Database (choose one) SQLALCHEMY_DATABASE_URI=sqlite:///enferno.sqlite3 # Or for PostgreSQL: # SQLALCHEMY_DATABASE_URI=postgresql://username:password@localhost/dbname # Redis & Celery REDIS_URL=redis://localhost:6379/0 CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/2 # Email Settings (optional) MAIL_SERVER=smtp.example.com MAIL_PORT=465 MAIL_USE_SSL=True MAIL_USERNAME=your_email MAIL_PASSWORD=your_password SECURITY_EMAIL_SENDER=noreply@example.com # OAuth (optional) GOOGLE_AUTH_ENABLED=true GOOGLE_OAUTH_CLIENT_ID=your_client_id GOOGLE_OAUTH_CLIENT_SECRET=your_client_secret GITHUB_AUTH_ENABLED=true GITHUB_OAUTH_CLIENT_ID=your_client_id GITHUB_OAUTH_CLIENT_SECRET=your_client_secret # Security Settings SECURITY_PASSWORD_SALT=your_secure_salt SECURITY_TOTP_SECRETS=your_totp_secrets ``` -------------------------------- ### Create Enferno Systemd Service File - INI Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Defines a Systemd service unit file for the main Enferno web application, specifying how to start it using Gunicorn within its virtual environment. ```ini [Unit] Description=Enferno Web Application After=network.target [Service] User=your_user WorkingDirectory=/path/to/enferno Environment="PATH=/path/to/enferno/venv/bin" ExecStart=/path/to/enferno/venv/bin/gunicorn -w 4 -b 127.0.0.1:5000 wsgi:app [Install] WantedBy=multi-user.target ``` -------------------------------- ### Running Celery Worker Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Provides the command-line instruction to start a Celery worker process for the Enferno application. The `-A enferno.tasks` specifies the application module, and `--loglevel=info` sets the logging level. ```Bash celery -A enferno.tasks worker --loglevel=info ``` -------------------------------- ### Obtain SSL Certificate with Certbot - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Runs Certbot with the Nginx plugin to automatically obtain and install an SSL certificate for the specified domain, configuring Nginx accordingly. ```bash sudo certbot --nginx -d yourdomain.com ``` -------------------------------- ### Update System Packages - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Updates the list of available packages and upgrades all installed packages on the Ubuntu server to their latest versions. ```bash sudo apt update sudo apt upgrade -y ``` -------------------------------- ### View Enferno Systemd Logs (Shell) Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Execute this command with root privileges to view the systemd journal logs for the 'enferno' service, providing insights into why the application might not be starting correctly. ```Shell sudo journalctl -u enferno ``` -------------------------------- ### Start Conditional Block (Templating Language) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/welcome.txt Initiates a conditional block that renders subsequent content only if the expression 'security.confirmable' evaluates to true. This is used to control the visibility of template sections, such as an email confirmation link. ```Templating Language {% if security.confirmable %} ``` -------------------------------- ### Create Celery Worker Systemd Service File - INI Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Defines a Systemd service unit file for the Enferno Celery worker, specifying how to start it within its virtual environment. ```ini [Unit] Description=Enferno Celery Worker After=network.target [Service] User=your_user WorkingDirectory=/path/to/enferno Environment="PATH=/path/to/enferno/venv/bin" ExecStart=/path/to/enferno/venv/bin/celery -A enferno.tasks worker --loglevel=info [Install] WantedBy=multi-user.target ``` -------------------------------- ### Performing SQLAlchemy CRUD Operations Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Demonstrates common Create, Read (querying), Update, and Delete (CRUD) operations using SQLAlchemy 2.x session methods. Shows examples of adding, querying (all, by ID, filtered, joined), updating, and deleting `Post` objects. ```Python from enferno.extensions import db from enferno.models import Post from sqlalchemy import select # Create post = Post(title='New Post', content='Content here') db.session.add(post) db.session.commit() # Simple queries stmt = db.session.select(Post) # Select all posts posts = db.session.scalars(stmt).all() post = db.session.get(Post, 1) # Get by ID # Filtered query stmt = db.session.select(Post).where(Post.title.like('%python%')) python_posts = db.session.scalars(stmt).all() # Ordered query with join stmt = ( db.session.select(Post) .join(Post.user) .order_by(Post.created_at.desc()) ) recent_posts = db.session.scalars(stmt).all() # Update post = db.session.get(Post, 1) post.title = 'Updated Title' db.session.commit() # Delete db.session.delete(post) db.session.commit() ``` -------------------------------- ### Running Celery Worker (Bash) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This command starts a Celery worker process for the Enferno project. It executes background tasks defined in `enferno.tasks`. The `--loglevel=info` flag sets the logging level for the worker. ```bash celery -A enferno.tasks worker --loglevel=info ``` -------------------------------- ### Project Dependencies List Source: https://github.com/level09/enferno/blob/master/requirements.txt This list specifies the exact versions of Python packages required to run the project. It is typically used with pip install -r requirements.txt to ensure a consistent environment. ```Python amqp==5.3.1 Babel==2.17.0 bcrypt==4.3.0 bleach==6.2.0 blinker==1.9.0 celery==5.5.1 cffi==1.17.1 click==8.1.8 cryptography==44.0.2 email-validator==2.2.0 Flask==3.1.0 Flask-Caching==2.3.1 Flask-Dance==7.1.0 Flask-DebugToolbar==0.16.0 Flask-Login==0.6.3 Flask-Mail==0.10.0 Flask-Script==2.0.6 Flask-Security-Too==5.6.1 Flask-Session==0.8.0 Flask-SQLAlchemy==3.1.1 Flask-WTF==1.2.2 itsdangerous==2.2.0 Jinja2==3.1.6 kombu==5.5.3 Mako==1.3.10 MarkupSafe==3.0.2 passlib==1.7.4 Pillow==11.2.1 psycopg2-binary==2.9.10 pycparser==2.22 python-dateutil==2.9.0.post0 python-dotenv==1.1.0 python-editor==1.0.4 pytz==2025.2 qrcode==8.1 redis==5.2.1 six==1.17.0 speaklater==1.3 SQLAlchemy==2.0.40 uWSGI==2.0.29 vine==5.1.0 Werkzeug==3.1.3 webauthn==2.5.2 WTForms==3.2.1 orjson==3.10.16 flask-babel==4.0.0 rich==14.0.0 setuptools>=78.1.0 ``` -------------------------------- ### End Conditional Block (Templating Language) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/welcome.txt Closes the most recent conditional block started by an 'if' or similar tag. Content after this tag is rendered unconditionally unless it is part of another nested block. ```Templating Language {% endif %} ``` -------------------------------- ### Flask RESTful API Endpoint (Python) Source: https://github.com/level09/enferno/blob/master/docs/cursor-rules.mdx This Python snippet demonstrates a Flask route defined as a RESTful API endpoint for fetching resources. It uses `methods=['GET']`, queries the database using SQLAlchemy, retrieves all results, and returns them as a JSON array using `jsonify` and a `to_dict()` method on the resource objects. ```python @api.route('/resources', methods=['GET']) def get_resources(): stmt = db.session.select(Resource) resources = db.session.scalars(stmt).all() return jsonify([resource.to_dict() for resource in resources]) ``` -------------------------------- ### Initialize Database and Admin User Source: https://github.com/level09/enferno/blob/master/README.md Flask CLI commands to set up the database schema and create an initial admin user for the application. ```Bash flask create-db # Setup database flask install # Create admin user ``` -------------------------------- ### Initialize Database and Admin User - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Activates the Python virtual environment and runs Flask commands to initialize the database schema and create the initial admin user. ```bash source .venv/bin/activate flask create-db flask install ``` -------------------------------- ### Create PostgreSQL User and Database - Bash Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Uses the PostgreSQL `createuser` and `createdb` commands via the `sudo -u postgres` user to set up a dedicated user and database for the Enferno application. ```bash sudo -u postgres createuser -s myuser sudo -u postgres createdb mydb ``` -------------------------------- ### Initializing Flask Debug Toolbar (Python) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This snippet initializes the Flask Debug Toolbar extension for the application. The toolbar provides insights into requests, configurations, database queries, and more during development. Requires Flask-DebugToolbar and an initialized Flask app instance. ```python from flask_debugtoolbar import DebugToolbarExtension toolbar = DebugToolbarExtension(app) ``` -------------------------------- ### Security Configuration Settings Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Lists essential security configuration settings typically stored in a `.env` file. These include password salt, TOTP secrets, and flags controlling features like registration, confirmation, recovery, tracking, password length, and token expiration. ```bash # Security Settings SECURITY_PASSWORD_SALT=your_secure_salt SECURITY_TOTP_SECRETS=your_totp_secrets SECURITY_REGISTERABLE=true SECURITY_CONFIRMABLE=true SECURITY_RECOVERABLE=true SECURITY_TRACKABLE=true SECURITY_PASSWORD_LENGTH_MIN=8 SECURITY_TOKEN_MAX_AGE=86400 ``` -------------------------------- ### OAuth Integration Configuration Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Configure Google and GitHub OAuth credentials and enable social login using environment variables. These settings include client IDs and secrets required for the OAuth flow. ```bash # Google OAuth GOOGLE_AUTH_ENABLED=true GOOGLE_OAUTH_CLIENT_ID=your_client_id GOOGLE_OAUTH_CLIENT_SECRET=your_client_secret # GitHub OAuth GITHUB_AUTH_ENABLED=true GITHUB_OAUTH_CLIENT_ID=your_client_id GITHUB_OAUTH_CLIENT_SECRET=your_client_secret ``` -------------------------------- ### Display Login Link (Templating) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/login_instructions.txt This snippet uses a template variable to display the login link for the user. ```Templating {{ login_link }} ``` -------------------------------- ### Configure OAuth Environment Variables Source: https://github.com/level09/enferno/blob/master/docs/introduction.mdx This snippet shows the required environment variables to configure Google and GitHub OAuth integration within the Enferno framework's `.env` file. Replace the placeholder values with your actual client IDs and secrets obtained from the respective OAuth providers. ```bash # Google OAuth GOOGLE_AUTH_ENABLED=true GOOGLE_OAUTH_CLIENT_ID=your_client_id GOOGLE_OAUTH_CLIENT_SECRET=your_client_secret # GitHub OAuth GITHUB_AUTH_ENABLED=true GITHUB_OAUTH_CLIENT_ID=your_client_id GITHUB_OAUTH_CLIENT_SECRET=your_client_secret ``` -------------------------------- ### Initializing Flask-WTF CSRF Protection (Python) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This snippet initializes CSRF protection for the Flask application using Flask-WTF's `CSRFProtect`. It helps prevent Cross-Site Request Forgery attacks by requiring a valid CSRF token for form submissions. Requires Flask-WTF and an initialized Flask app instance. ```python from flask_wtf.csrf import CSRFProtect csrf = CSRFProtect(app) ``` -------------------------------- ### Session Configuration Settings Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Displays configuration options related to session security. These settings control the session protection level, lifetime, and cookie flags (`Secure`, `HttpOnly`, `SameSite`) to enhance session security. ```bash # Session Configuration SESSION_PROTECTION = 'strong' PERMANENT_SESSION_LIFETIME = timedelta(days=1) SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SESSION_COOKIE_SAMESITE = 'Lax' ``` -------------------------------- ### Defining SQLAlchemy Model (Post) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Defines the `Post` SQLAlchemy model, mapping it to a database table. It includes columns for ID, title, content, creation timestamp, and a foreign key relationship to a `User` model. ```Python from enferno.extensions import db from datetime import datetime class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80), nullable=False) content = db.Column(db.Text) created_at = db.Column(db.DateTime, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', back_populates='posts') ``` -------------------------------- ### Defining Flask API Endpoint (Python) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This snippet defines a Flask blueprint and an endpoint `/posts` to retrieve all posts from the database. It uses SQLAlchemy to query the `Post` model, orders results by creation date, and returns them as a JSON array. Requires Flask, Flask-SQLAlchemy, and the Post model. ```python from flask import Blueprint, jsonify from app.extensions import db from app.models import Post api = Blueprint('api', __name__) @api.route('/posts') def get_posts(): query = db.select(Post).order_by(Post.created_at.desc()) posts = db.session.execute(query).scalars() return jsonify([{ 'id': post.id, 'title': post.title, 'content': post.content } for post in posts]) ``` -------------------------------- ### User Registration Endpoint Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Implements a user registration endpoint that accepts POST requests. It uses a `RegisterForm` for validation and creates a new `User` instance with email, password, and active status upon successful validation. ```python from enferno.user.models import User from enferno.user.forms import RegisterForm @app.route('/register', methods=['POST']) def register(): form = RegisterForm() if form.validate_on_submit(): user = User( email=form.email.data, password=form.password.data, active=True ) user.save() return jsonify({'message': 'Registration successful'}) return jsonify(form.errors), 400 ``` -------------------------------- ### Flask Blueprint Organization with Authentication (Python) Source: https://github.com/level09/enferno/blob/master/docs/cursor-rules.mdx This Python snippet illustrates the organization of Flask routes using a Blueprint. It includes importing necessary modules, creating a Blueprint instance, and applying an authentication requirement (`@auth_required()`) to all routes within the blueprint using `@before_request`. ```python # Blueprint organization from flask import Blueprint from flask_security import auth_required portal = Blueprint('portal', __name__) @portal.before_request @auth_required() def before_request(): pass @portal.route('/dashboard') def dashboard(): return render_template('portal/dashboard.html') ``` -------------------------------- ### Display Confirmation Link (Templating Language) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/welcome.txt Interpolates and displays the value of the 'confirmation_link' variable. This variable is typically a URL provided to the template context that allows the user to confirm their email address. ```Templating Language {{ confirmation_link }} ``` -------------------------------- ### Configure PostgreSQL in .env - Configuration Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Sets the `SQLALCHEMY_DATABASE_URI` variable in the application's `.env` file to connect to the configured PostgreSQL database. ```ini SQLALCHEMY_DATABASE_URI=postgresql://myuser:password@localhost/mydb ``` -------------------------------- ### Collect Flask Static Files (Shell) Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Use this command, likely part of the Enferno CLI, to gather and prepare static assets for deployment, which can help resolve 404 errors for static files. ```Shell flask static ``` -------------------------------- ### Enabling SQLAlchemy Query Logging (Python) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This snippet enables logging for SQLAlchemy engine operations, specifically SQL queries. Setting the logger level to `INFO` will print executed SQL statements to the console, which is useful for debugging database interactions. Requires the standard `logging` library and SQLAlchemy. ```python # Enable SQLAlchemy query logging logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) ``` -------------------------------- ### Configuring Basic Python Logging Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This snippet configures basic logging for the application using Python's built-in `logging` module. It sets the root logger's level to `DEBUG`, allowing all messages from DEBUG level and above to be processed. Requires the standard `logging` library. ```python import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) ``` -------------------------------- ### Display User Email (Templating) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/login_instructions.txt This snippet uses a template variable to display the email address of the user. ```Templating {{ user.email }} ``` -------------------------------- ### Display User Email (Templating Language) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/welcome.txt Interpolates and displays the value of the 'user.email' variable within the template. This is typically used to personalize the greeting or address the recipient. ```Templating Language {{ user.email }} ``` -------------------------------- ### Flask Route with Jinja Template Rendering (Python) Source: https://github.com/level09/enferno/blob/master/docs/cursor-rules.mdx This Python snippet shows a basic Flask route definition that renders an HTML template using `render_template`. It passes data (`products`) and a flag (`vue_enabled`) to the template context. ```python # Template example @app.route('/products') def products(): return render_template('products.html', products=products, vue_enabled=True) ``` -------------------------------- ### Defining Public Flask Blueprint (Public) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Defines the 'public' Flask Blueprint, intended for routes that do not require authentication. Includes a sample '/' route that is publicly accessible. ```Python from flask import Blueprint public = Blueprint('public', __name__) @public.route('/') def index(): return render_template('public/index.html') ``` -------------------------------- ### Configure Nginx Server Block - Nginx Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Provides a basic Nginx server block configuration to proxy requests to the Enferno application running on localhost:5000 and serve static files. ```nginx server { listen 80; server_name yourdomain.com; location / { proxy_pass http://127.0.0.1:5000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /static { alias /path/to/enferno/static; expires 30d; } } ``` -------------------------------- ### Vuetify Dialog Component Pattern (HTML) Source: https://github.com/level09/enferno/blob/master/docs/cursor-rules.mdx This HTML snippet provides a recommended pattern for implementing a Vuetify dialog component. It shows the use of `v-dialog`, `v-slot:activator` for the button, and basic `v-card` structure for the dialog content. ```html Dialog Title Content here ``` -------------------------------- ### Check Redis Service Status (Shell) Source: https://github.com/level09/enferno/blob/master/docs/deployment.mdx Run this command with root privileges to check the current status of the Redis service managed by systemd, a key step in diagnosing Redis connection issues. ```Shell sudo systemctl status redis ``` -------------------------------- ### Defining Authenticated Flask Blueprint Route (User) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Defines the 'user' Flask Blueprint and a sample '/profile' route. This route is explicitly protected using the `auth_required` decorator, requiring user authentication to access. ```Python from flask import Blueprint from flask_security import auth_required user = Blueprint('user', __name__) @user.route('/profile') @auth_required() def profile(): return render_template('user/profile.html') ``` -------------------------------- ### Calling Celery Task Asynchronously Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Demonstrates how to call a defined Celery task (`send_email`) asynchronously from within the application using the `.delay()` method. This offloads the task execution to a Celery worker. ```Python from enferno.tasks import send_email # Call task asynchronously send_email.delay(user.id, 'Welcome', 'Welcome to Enferno!') ``` -------------------------------- ### Jinja Template with Vue Component and Raw Tag (HTML) Source: https://github.com/level09/enferno/blob/master/docs/cursor-rules.mdx This HTML snippet demonstrates integrating a Vue component (`v-data-table`) within a Jinja template. It uses the `{% raw %}` tag to prevent Jinja from processing Vue's double-curly brace syntax (`{{ products }}`). ```html {% extends "layout.html" %} {% block content %}
{% endblock %} ``` -------------------------------- ### Applying Flask-Security Authentication (Python) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This Python snippet demonstrates how to protect a route using the `@auth_required()` decorator from Flask-Security. Applying this decorator ensures that only authenticated users can access the `/protected` endpoint. Requires Flask-Security configured with authentication. ```python from flask_security import auth_required @app.route('/protected') @auth_required() def protected_route(): return 'Protected content' ``` -------------------------------- ### Defining Protected Flask Blueprint (Portal) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Defines the 'portal' Flask Blueprint, typically used for protected routes. It automatically applies the `auth_required` decorator to all routes within this blueprint using a `before_request` handler, ensuring authentication is required for access. ```Python from flask import Blueprint from flask_security import auth_required portal = Blueprint('portal', __name__) # Protect all routes in this blueprint automatically @portal.before_request @auth_required() def before_request(): pass @portal.route('/dashboard') def dashboard(): return render_template('portal/dashboard.html') @portal.route('/settings') def settings(): return render_template('portal/settings.html') ``` -------------------------------- ### Rate Limiting Configuration Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Configures rate limiting for the Flask application using Flask-Limiter. It applies a default rate limit globally and a stricter limit specifically to the login endpoint to mitigate brute force attacks based on the client's remote address. ```python from flask_limiter import Limiter from flask_limiter.util import get_remote_address limiter = Limiter( app, key_func=get_remote_address, default_limits=["200 per day", "50 per hour"] ) @app.route('/login', methods=['POST']) @limiter.limit("5 per minute") def login(): # Login logic here pass ``` -------------------------------- ### Implementing Flask-WTF Input Validation (Python) Source: https://github.com/level09/enferno/blob/master/docs/development.mdx This Python snippet defines a Flask-WTF form class `PostForm` for validating input data. It includes a `title` field with `DataRequired` and `Length` validators to ensure the title is present and within a maximum length. Requires Flask-WTF and WTForms. ```python from flask_wtf import FlaskForm from wtforms import StringField from wtforms.validators import DataRequired, Length class PostForm(FlaskForm): title = StringField('Title', validators=[ DataRequired(), Length(max=80) ]) ``` -------------------------------- ### Role-Based Access Control Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Demonstrates using Flask-Security-Too decorators (`roles_required`, `roles_accepted`) to restrict access to routes based on user roles. The `@roles_required` decorator restricts access to users with a specific role, while `@roles_accepted` allows access for users with any of the listed roles. ```python from flask_security import roles_required, roles_accepted @app.route('/admin') @roles_required('admin') def admin_dashboard(): return 'Admin only content' @app.route('/premium') @roles_accepted('premium', 'admin') def premium_content(): return 'Premium or admin content' ``` -------------------------------- ### Generate User Authentication Token Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Provides a utility function to generate an authentication token for a given user object. It returns the generated token string and its expiration timestamp, typically used after successful login. ```python from flask_security.utils import get_token_status def generate_auth_token(user): token = user.get_auth_token() return jsonify({ 'token': token, 'expires': get_token_status(token)['exp'] }) ``` -------------------------------- ### Defining Celery Background Task Source: https://github.com/level09/enferno/blob/master/docs/development.mdx Defines a Celery task named `send_email` using the `@celery.task` decorator. This task is intended to run in the background, fetching a user from the database and performing an action like sending an email. ```Python from enferno.tasks import celery @celery.task def send_email(user_id, subject, message): from enferno.extensions import db from enferno.user.models import User user = db.session.get(User, user_id) # Send email to user... return True ``` -------------------------------- ### Two-Factor Authentication Required Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Illustrates how to enforce two-factor authentication for accessing a specific route. The `@two_factor_required` decorator ensures that the user has completed the 2FA challenge before the route handler is executed. ```python from flask_security import two_factor_required @app.route('/sensitive') @two_factor_required def sensitive_data(): return 'Two-factor authenticated content' ``` -------------------------------- ### WebAuthn Authentication Required Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Shows how to protect a route requiring WebAuthn (passwordless) authentication. The `@webauthn_required` decorator ensures the user has successfully authenticated using a registered WebAuthn credential. ```python from flask_security import webauthn_required @app.route('/webauthn-protected') @webauthn_required def webauthn_protected(): return 'WebAuthn authenticated content' ``` -------------------------------- ### Display Conditional Password Reset Link (Jinja2) Source: https://github.com/level09/enferno/blob/master/enferno/templates/security/email/change_notice.txt Checks if password recovery is enabled (`security.recoverable`). If true, it displays a message and a link generated by `url_for_security` to the 'forgot_password' route, ensuring the link is absolute (`_external=True`). This allows users to reset their password if they did not initiate the change. ```Jinja2 {% if security.recoverable %} If you did not change your password, click the link below to reset it. {{ url_for_security('forgot_password', _external=True) }} {% endif %} ``` -------------------------------- ### Token-Based API Authentication Source: https://github.com/level09/enferno/blob/master/docs/authentication.mdx Protects an API endpoint requiring a valid authentication token using the `auth_token_required` decorator. The `@auth_token_required` decorator ensures that a valid authentication token is present in the request headers before allowing access to the endpoint. ```python from flask_security import auth_token_required @app.route('/api/protected') @auth_token_required def protected_endpoint(): return jsonify({'message': 'Authenticated access'}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.