Metadata-Version: 2.1
Name: TT-auth-system
Version: 0.1.0
Summary: An authentication system with one-time login links and templated email sending
Home-page: https://github.com/jarod-johnson-23/TT24_otc_generator
Author: Jarod Johnson
Author-email: jarodjohnson1001@gmail.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: python-dotenv
Requires-Dist: jinja2

# OTC Auth System

This OTC Auth system is a Python package that provides a simple authentication mechanism using one-time login links. Users receive an email containing a unique login link, generated by the package, which allows them to authenticate without a password. This package is intended to be integrated into larger projects, providing reusable authentication functionality.

## Installation

To install the package, clone the repository or download the source code. Navigate to the root directory of the package and run:

pip install TT_auth_system

This command installs the package and its dependencies.

## Setup and Configuration

### Environment Variables

The package relies on several environment variables to configure its behavior, particularly for SMTP settings and the base URL of the login link. These should be set in a `.env` file in the root of the main project using the package.

Create a `.env` file with the following variables:

- **`SMTP_SERVER`**: The address of the SMTP server used to send emails (e.g., `smtp.example.com`).
- **`SMTP_PORT`**: The port number for the SMTP server (commonly `587` for TLS or `465` for SSL).
- **`SMTP_USERNAME`**: The username for SMTP authentication.
- **`SMTP_PASSWORD`**: The password for SMTP authentication.
- **`LOGIN_LINK_BASE_URL`**: The base URL for the login link sent to users. This should point to the part of your application that handles login (e.g., `https://yourapp.com/login`).

Example `.env` file:

SMTP_SERVER=smtp.example.com
SMTP_PORT=587
SMTP_USERNAME=your_smtp_username
SMTP_PASSWORD=your_smtp_password
LOGIN_LINK_BASE_URL=https://yourapp.com/login

### HTML Email Template

The package sends an HTML email containing the login link. The HTML template file should be placed in the `templates` directory at the root of the main project. The file should be named `otc_email.html`.

**Directory Structure:**
main_project/
├── .env
├── templates/
│ └── otc_email.html
├── main_script.py
└── auth_system/

**Example `otc_email.html`:**

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Link</title>
</head>
<body>
    <p>Dear user,</p>
    <p>Click the link below to log in:</p>
    <p><a href="{{ login_link }}">{{ login_link }}</a></p>
    <p>This link is valid for one-time use only.</p>
    <p>Best regards,<br>Your App Team</p>
</body>
</html>

The {{ login_link }} placeholder will be replaced with the actual login link when the email is sent.

## Usage

To use the package in your project, import the necessary functions and configure your environment:

from auth_system import generate_code, send_login_email, store_code, validate_code, purge_valid_codes

# Generate a one-time code

code = generate_code()

# Send a login email with the generated code

send_login_email("user@example.com", code)

# Store the generated code for later validation

store_code(code, "user@example.com")

# Validate a code (returns the associated email if valid, None otherwise)

is_valid = validate_code(code)

# Purge all valid codes from memory

purge_valid_codes()

## Dependencies

The package depends on the following Python libraries:

    •	python-dotenv: For loading environment variables from a .env file.
    •	jinja2: For rendering HTML templates.
    •	smtplib: Part of Python’s standard library, used for sending emails via SMTP.

These dependencies are automatically installed when you install the package using pip.

## License

This project is licensed under the MIT License. See the LICENSE file for details.
