### Installing Django E2EE Framework via PyPi - Bash Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/installation.rst This command installs the `django-e2ee-framework` package from the Python Package Index (PyPi) using pip, the standard package installer for Python. It's the recommended method for stable releases. ```bash pip install django-e2ee-framework ``` -------------------------------- ### Installing Django E2EE Framework from Gitlab Source - Bash Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/installation.rst This command installs the `django-e2ee-framework` package directly from its Gitlab source repository using pip. This method is typically used for accessing development versions or specific branches. ```bash pip install git+https://gitlab.hzdr.de/hcdc/django/django-e2ee-framework.git ``` -------------------------------- ### Setting up Django E2EE Framework for Development Source: https://github.com/keitheis/django-e2ee-framework/blob/main/README.rst This snippet outlines the steps to set up the `django-e2ee-framework` for development. It includes cloning the source code from GitLab, navigating into the directory, creating and activating a virtual environment, and running the development installation command. ```Shell git clone https://gitlab.hzdr.de/hcdc/django/django-e2ee-framework cd django-e2ee-framework python -m venv venv source venv/bin/activate make dev-install ``` -------------------------------- ### Configuring Django E2EE Framework URLs - Python Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/installation.rst This Python code snippet demonstrates how to include the `django_e2ee` app's URLs into a Django project's main `urls.py` file. It uses Django's `path` and `include` functions to route requests to the framework's endpoints. ```python from django.urls import include, path urlpatterns += [ path("django-e2ee-framework/", include("django_e2ee.urls")), ] ``` -------------------------------- ### Installing Django E2EE Framework in Development Mode (Python) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/contributing.rst This command installs the `django-e2ee-framework` package in editable development mode, including its development dependencies specified by the `[dev]` option. This setup allows for direct modification of the source code and immediate reflection of changes without reinstallation. ```bash pip install -e ./django-e2ee-framework/[dev] ``` -------------------------------- ### Running Database Migrations for Django E2EE Framework (Bash) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/contributing.rst After installing the package, these commands navigate into the project directory and execute Django's migration command. This process applies any pending database schema changes and sets up the necessary tables for the `django-e2ee-framework` application. ```bash cd django-e2ee-framework/ python manage.py migrate ``` -------------------------------- ### Installing Pre-Commit Hooks for Code Quality (Bash) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/contributing.rst This command installs pre-commit hooks for the repository, ensuring that code formatting, quality checks, and type checking tools (Black, blackdoc, Flake8, isort, mypy) are automatically run before each Git commit. This helps maintain consistent code style and quality across the project. ```bash pre-commit install ``` -------------------------------- ### Installing Django E2EE Framework via pip Source: https://github.com/keitheis/django-e2ee-framework/blob/main/README.rst This snippet demonstrates how to install the `django-e2ee-framework` package in a dedicated Python virtual environment using pip. It involves creating a virtual environment, activating it, and then installing the package. ```Shell python -m venv venv source venv/bin/activate pip install django-e2ee-framework ``` -------------------------------- ### Cloning a Forked Django E2EE Framework Repository (Bash) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/contributing.rst This command clones your forked `django-e2ee-framework` repository from GitLab to your local machine, allowing you to begin development. Remember to replace `` with your actual GitLab username. ```bash git clone https://gitlab.hzdr.de//django-e2ee-framework.git ``` -------------------------------- ### Manually Running All Pre-Commit Checks (Bash) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/docs/contributing.rst This command manually executes all configured pre-commit checks across all files in the repository. It is useful for verifying code quality and formatting before committing, or for fixing issues identified by the continuous integration (CI) pipeline. ```bash pre-commit run --all-files ``` -------------------------------- ### Declaring Python Project Dependencies Source: https://github.com/keitheis/django-e2ee-framework/blob/main/requirements.txt This snippet lists the external Python packages required for the project to run. It specifies 'requests' as a general dependency and 'Django' with a version constraint, ensuring compatibility between versions 3.1 and 3.3 (exclusive of 3.3). ```Python requests Django>=3.1,<3.3 ``` -------------------------------- ### Including Form Media JavaScript (Django Template) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/testproject/test_app/templates/test_app/home.html This snippet includes the necessary JavaScript media files for various Django forms used in the E2EE framework, such as the E2EE login form and password creation form, ensuring their proper functionality. ```Django Template {% if session_keys %} {% get_session_key_form session_keys.first as session_key_form %} {{ session_key_form.media.js }} {% endif %} {{ e2ee_login_form.media.js }} {% if request.session|e2ee_enabled %} {% get_password_create_form as password_create_form %} {{ password_create_form.media.js }} {% endif %} ``` -------------------------------- ### Displaying E2EE Login Forms and Status (Django Template) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/testproject/test_app/templates/test_app/home.html This snippet conditionally displays E2EE login forms based on the user's master key and session key status. It informs the user about the E2EE state (enabled, awaiting approval) and prompts for password entry or creation. ```Django Template {% if not user.master_key %} {{ e2ee_login_form }} {% elif not request.session|has_session_key %} Enter your E2EE password to read end-to-end-encrypted messages {{ e2ee_login_form }} or identify through a different session. {% elif request.session|e2ee_enabled %} End-to-end encryption is enabled and you are all fine! If you like, you can add another E2EE password: {% get_password_create_form %} {% else %} End-to-end encryption is awaiting approval through other session. {% endif %} ``` -------------------------------- ### Listing and Managing Active E2EE Sessions (Django Template) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/testproject/test_app/templates/test_app/home.html This snippet retrieves and iterates through active E2EE session keys, displaying each session. If a session key's secret is not available, it provides a form to enter or verify it, enabling management of multiple E2EE sessions. ```Django Template {% get_session_keys as session_keys %} {% if session_keys %} Your active sessions -------------------- {% for session_key in session_keys %}* {{ session_key }} {% if not session_key.secret %} {% get_session_key_form session_key %} {% endif %} {% endfor %} {% endif %} ``` -------------------------------- ### Registering Service Worker for E2EE (JavaScript) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/testproject/test_app/templates/test_app/home.html This JavaScript snippet registers a service worker for the application, essential for enabling end-to-end encryption functionalities. It provides feedback on the registration status and alerts the user if service workers are not supported by their browser. ```JavaScript if ('serviceWorker' in navigator) { navigator.serviceWorker.register('{% url "test_app:serviceworker" %}') .then(function () { let elem = document.getElementById("serviceworker-report"); // for some reasons, firefox does need a bit more time... setTimeout( function() { elem.innerHTML = "Serviceworker registered"}, 500 ); }); } else { window.addEventListener('load', function() { let elem = document.getElementById("missing-serviceworker-message") elem.innerHTML = "Serviceworkers are not available in this browser. E2EE will not work!" }); } ``` -------------------------------- ### Updating Session Key Verification Report (JavaScript) Source: https://github.com/keitheis/django-e2ee-framework/blob/main/testproject/test_app/templates/test_app/home.html This asynchronous JavaScript function processes a server response to update a UI element with a session key verification number. It's used to display a number that users need to enter on another device for cross-device session verification. ```JavaScript async function updateSessionKeyVerificationReport(response) { let body = await response.json() document.getElementById('sessionKeyVerificationReport').innerHTML = `

On your other device, please enter the following number:

${body.verificationNumber}

` } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.