RedXAuthCodes


NameRedXAuthCodes JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/redxdev/redxauthcodes
SummaryA comprehensive authentication and verification API platform providing secure, scalable identity management
upload_time2025-01-29 00:01:14
maintainerNone
docs_urlNone
authorRedXDev
requires_python>=3.9
licenseMIT
keywords authentication verification email notification security subscription
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RedXAuthCodes

A powerful and secure authentication code generation and verification system with built-in email integration and subscription management.

## Features

- Secure verification code generation with checksum validation
- Email integration for code delivery
- Subscription management system with expiration handling
- PostgreSQL database backend (works with any PostgreSQL database, including free ones)
- Rate limiting and security features
- RedXSecurePayments integration support
- Comprehensive logging and error handling
- Interactive tutorial for new users

## Installation

Basic installation:
```bash
pip install RedXAuthCodes
```

With RedXSecurePayments integration:
```bash
pip install "RedXAuthCodes[redx]"
```

## Quick Start Tutorial

Get started quickly with our interactive tutorial:

```bash
# After installation, run:
python -m RedXAuthCodes.tutorial.cli

# Or use the convenience script:
python tutorial.py
```

The tutorial will guide you through:
1. Generating verification codes
2. Sending email verifications
3. Managing subscriptions
4. Payment integration

Perfect for new users to learn the basics!

## Database Setup Options

1. **Free Replit Database** (Recommended for development):
   - Automatically created when hosting on Replit
   - No additional configuration needed
   - Perfect for development and testing

2. **External PostgreSQL Database**:
   - Use any PostgreSQL provider (e.g., Railway, Supabase, AWS RDS)
   - Many providers offer free tiers
   - Configure via DATABASE_URL environment variable

## Environment Setup

Required environment variables:
```bash
# Database Configuration (Use ONE of these options)
# Option 1: Use individual connection parameters
PGHOST=your-db-host
PGPORT=5432
PGUSER=your-db-user
PGPASSWORD=your-db-password
PGDATABASE=your-db-name

# Option 2: Use connection URL
DATABASE_URL=postgresql://user:password@host:port/dbname

# Email Configuration
SENDER_EMAIL=your-sender@email.com
EMAIL_APP_PASSWORD=your-email-app-password

# For RedXSecurePayments Integration (optional)
STRIPE_SECRET_KEY=your-stripe-secret-key
```

## Basic Usage (Standalone)

### 1. Code Generation and Verification

```python
from RedXAuthCodes import RedXCode, EmailService

# Initialize services
code_generator = RedXCode()
email_service = EmailService()

# Generate a verification code
code_result = code_generator.Generate(
    email="user@example.com",
    length=8,  # Code length (default: 8)
    expiry_minutes=15  # Code expiration time (default: 15)
)

if code_result:
    code, created_at, expires_at = code_result
    print(f"Generated Code: {code}")
    print(f"Created at: {created_at}")
    print(f"Expires at: {expires_at}")

    # Send verification code via email
    email_service.send_verification_code(
        recipient_email="user@example.com",
        code=code
    )

# Verify a code
is_valid = code_generator.IsValid(code)
if is_valid:
    # Activate the code
    success = code_generator.Initiate(code)
```

### 2. Subscription Management

```python
from RedXAuthCodes import SubscriptionService

subscription_service = SubscriptionService()

# Create a new subscription
subscription = subscription_service.create_subscription(
    email="user@example.com",
    plan_type="Premium",
    duration_days=30,
    custom_message="Welcome to Premium!"
)

# Check subscription status
status = subscription_service.check_subscription("user@example.com")
if status.get('active'):
    print("Subscription is active")
    print(f"Expires at: {status['expiration_time']}")

# Cancel subscription
cancelled = subscription_service.resign_subscription("user@example.com")
```

## Integration with RedXSecurePayments

Example of complete purchase flow with payment processing:

```python
import RedXSecurePayments
from RedXAuthCodes import RedXCode, EmailService, SubscriptionService

def process_purchase(email: str, package_type: str = "complete"):
    # Initialize services
    code_generator = RedXCode()
    email_service = EmailService()
    subscription_service = SubscriptionService()

    # Set package price
    prices = {
        "auth_code": 5.00,
        "subscription": 10.00,
        "complete": 15.00
    }
    amount = prices.get(package_type, 15.00)

    # Step 1: Process payment
    payment_result = RedXSecurePayments.RedXSecureBuy(
        bank_name="Auth Package",
        currency_type="usd",
        currency_amount=amount,
        enable_multiple_payments=False,
        enable_custom_amount=False,
        enable_payment_history=True
    )

    if not payment_result['success']:
        return {"success": False, "error": "Payment failed"}

    # Step 2: Verify payment completion
    status = RedXSecurePayments.get_payment_status(
        payment_result['session_id']
    )

    if not status['success'] or status['status'] != 'completed':
        return {"success": False, "error": "Payment verification failed"}

    result = {"success": True}

    # Step 3: Generate verification code if needed
    if package_type in ["auth_code", "complete"]:
        code_result = code_generator.Generate(
            email=email,
            length=8,
            expiry_minutes=15
        )

        if code_result:
            code, created_at, expires_at = code_result
            result.update({
                "code": code,
                "code_expires": expires_at
            })

            # Send verification email
            email_service.send_verification_code(email, code)

    # Step 4: Create subscription if needed
    if package_type in ["subscription", "complete"]:
        subscription = subscription_service.create_subscription(
            email=email,
            plan_type="Premium",
            duration_days=30,
            custom_message="Thank you for subscribing!"
        )

        if subscription:
            result["subscription"] = subscription

    return result

# Example usage
result = process_purchase("user@example.com", "complete")
if result["success"]:
    print(f"Code: {result.get('code')}")
    print(f"Code expires: {result.get('code_expires')}")
    if 'subscription' in result:
        print(f"Subscription active until: {result['subscription']['expiration_time']}")
```

## API Reference

### RedXCode

- `Generate(email: str, length: int = 8, expiry_minutes: int = 15)` 
  - Generates a secure verification code
  - Returns tuple (code, created_at, expires_at) or None

- `IsValid(code: str) -> bool`
  - Checks if a code is valid and not expired

- `Initiate(code: str) -> bool`
  - Activates a verification code
  - Returns True if successful

- `RemoveData(email: str) -> bool`
  - Removes all codes for an email address

### EmailService

- `send_verification_code(recipient_email: str, code: str) -> bool`
  - Sends verification code via email

- `RedXSubEmail(recipient_email: str, expiration_time: str, custom_message: str = "") -> bool`
  - Sends subscription confirmation email

### SubscriptionService

- `create_subscription(email: str, plan_type: str, duration_days: int, custom_message: str = "") -> Dict`
  - Creates a new subscription
  - Returns subscription details or error message

- `check_subscription(email: str) -> Dict`
  - Checks subscription status
  - Returns subscription details or {"active": False}

- `resign_subscription(email: str) -> bool`
  - Cancels active subscription

## Security Features

- Secure code generation with checksums
- Automatic code expiration handling
- Rate limiting on API endpoints
- Email verification
- Secure database storage with PostgreSQL
- Payment verification integration
- Subscription expiration management

## Best Practices

1. Always verify payment completion before generating codes or creating subscriptions
2. Use environment variables for sensitive data
3. Implement proper error handling
4. Monitor rate limits
5. Regular cleanup of expired codes
6. Keep subscriptions updated
7. Use secure email configuration

## Support

For issues and feature requests, please visit our GitHub repository: https://github.com/redxdev/redxauthcodes

## License

MIT License - See LICENSE file for details

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/redxdev/redxauthcodes",
    "name": "RedXAuthCodes",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "authentication, verification, email, notification, security, subscription",
    "author": "RedXDev",
    "author_email": "RedXDev <redx@example.com>",
    "download_url": null,
    "platform": null,
    "description": "# RedXAuthCodes\n\nA powerful and secure authentication code generation and verification system with built-in email integration and subscription management.\n\n## Features\n\n- Secure verification code generation with checksum validation\n- Email integration for code delivery\n- Subscription management system with expiration handling\n- PostgreSQL database backend (works with any PostgreSQL database, including free ones)\n- Rate limiting and security features\n- RedXSecurePayments integration support\n- Comprehensive logging and error handling\n- Interactive tutorial for new users\n\n## Installation\n\nBasic installation:\n```bash\npip install RedXAuthCodes\n```\n\nWith RedXSecurePayments integration:\n```bash\npip install \"RedXAuthCodes[redx]\"\n```\n\n## Quick Start Tutorial\n\nGet started quickly with our interactive tutorial:\n\n```bash\n# After installation, run:\npython -m RedXAuthCodes.tutorial.cli\n\n# Or use the convenience script:\npython tutorial.py\n```\n\nThe tutorial will guide you through:\n1. Generating verification codes\n2. Sending email verifications\n3. Managing subscriptions\n4. Payment integration\n\nPerfect for new users to learn the basics!\n\n## Database Setup Options\n\n1. **Free Replit Database** (Recommended for development):\n   - Automatically created when hosting on Replit\n   - No additional configuration needed\n   - Perfect for development and testing\n\n2. **External PostgreSQL Database**:\n   - Use any PostgreSQL provider (e.g., Railway, Supabase, AWS RDS)\n   - Many providers offer free tiers\n   - Configure via DATABASE_URL environment variable\n\n## Environment Setup\n\nRequired environment variables:\n```bash\n# Database Configuration (Use ONE of these options)\n# Option 1: Use individual connection parameters\nPGHOST=your-db-host\nPGPORT=5432\nPGUSER=your-db-user\nPGPASSWORD=your-db-password\nPGDATABASE=your-db-name\n\n# Option 2: Use connection URL\nDATABASE_URL=postgresql://user:password@host:port/dbname\n\n# Email Configuration\nSENDER_EMAIL=your-sender@email.com\nEMAIL_APP_PASSWORD=your-email-app-password\n\n# For RedXSecurePayments Integration (optional)\nSTRIPE_SECRET_KEY=your-stripe-secret-key\n```\n\n## Basic Usage (Standalone)\n\n### 1. Code Generation and Verification\n\n```python\nfrom RedXAuthCodes import RedXCode, EmailService\n\n# Initialize services\ncode_generator = RedXCode()\nemail_service = EmailService()\n\n# Generate a verification code\ncode_result = code_generator.Generate(\n    email=\"user@example.com\",\n    length=8,  # Code length (default: 8)\n    expiry_minutes=15  # Code expiration time (default: 15)\n)\n\nif code_result:\n    code, created_at, expires_at = code_result\n    print(f\"Generated Code: {code}\")\n    print(f\"Created at: {created_at}\")\n    print(f\"Expires at: {expires_at}\")\n\n    # Send verification code via email\n    email_service.send_verification_code(\n        recipient_email=\"user@example.com\",\n        code=code\n    )\n\n# Verify a code\nis_valid = code_generator.IsValid(code)\nif is_valid:\n    # Activate the code\n    success = code_generator.Initiate(code)\n```\n\n### 2. Subscription Management\n\n```python\nfrom RedXAuthCodes import SubscriptionService\n\nsubscription_service = SubscriptionService()\n\n# Create a new subscription\nsubscription = subscription_service.create_subscription(\n    email=\"user@example.com\",\n    plan_type=\"Premium\",\n    duration_days=30,\n    custom_message=\"Welcome to Premium!\"\n)\n\n# Check subscription status\nstatus = subscription_service.check_subscription(\"user@example.com\")\nif status.get('active'):\n    print(\"Subscription is active\")\n    print(f\"Expires at: {status['expiration_time']}\")\n\n# Cancel subscription\ncancelled = subscription_service.resign_subscription(\"user@example.com\")\n```\n\n## Integration with RedXSecurePayments\n\nExample of complete purchase flow with payment processing:\n\n```python\nimport RedXSecurePayments\nfrom RedXAuthCodes import RedXCode, EmailService, SubscriptionService\n\ndef process_purchase(email: str, package_type: str = \"complete\"):\n    # Initialize services\n    code_generator = RedXCode()\n    email_service = EmailService()\n    subscription_service = SubscriptionService()\n\n    # Set package price\n    prices = {\n        \"auth_code\": 5.00,\n        \"subscription\": 10.00,\n        \"complete\": 15.00\n    }\n    amount = prices.get(package_type, 15.00)\n\n    # Step 1: Process payment\n    payment_result = RedXSecurePayments.RedXSecureBuy(\n        bank_name=\"Auth Package\",\n        currency_type=\"usd\",\n        currency_amount=amount,\n        enable_multiple_payments=False,\n        enable_custom_amount=False,\n        enable_payment_history=True\n    )\n\n    if not payment_result['success']:\n        return {\"success\": False, \"error\": \"Payment failed\"}\n\n    # Step 2: Verify payment completion\n    status = RedXSecurePayments.get_payment_status(\n        payment_result['session_id']\n    )\n\n    if not status['success'] or status['status'] != 'completed':\n        return {\"success\": False, \"error\": \"Payment verification failed\"}\n\n    result = {\"success\": True}\n\n    # Step 3: Generate verification code if needed\n    if package_type in [\"auth_code\", \"complete\"]:\n        code_result = code_generator.Generate(\n            email=email,\n            length=8,\n            expiry_minutes=15\n        )\n\n        if code_result:\n            code, created_at, expires_at = code_result\n            result.update({\n                \"code\": code,\n                \"code_expires\": expires_at\n            })\n\n            # Send verification email\n            email_service.send_verification_code(email, code)\n\n    # Step 4: Create subscription if needed\n    if package_type in [\"subscription\", \"complete\"]:\n        subscription = subscription_service.create_subscription(\n            email=email,\n            plan_type=\"Premium\",\n            duration_days=30,\n            custom_message=\"Thank you for subscribing!\"\n        )\n\n        if subscription:\n            result[\"subscription\"] = subscription\n\n    return result\n\n# Example usage\nresult = process_purchase(\"user@example.com\", \"complete\")\nif result[\"success\"]:\n    print(f\"Code: {result.get('code')}\")\n    print(f\"Code expires: {result.get('code_expires')}\")\n    if 'subscription' in result:\n        print(f\"Subscription active until: {result['subscription']['expiration_time']}\")\n```\n\n## API Reference\n\n### RedXCode\n\n- `Generate(email: str, length: int = 8, expiry_minutes: int = 15)` \n  - Generates a secure verification code\n  - Returns tuple (code, created_at, expires_at) or None\n\n- `IsValid(code: str) -> bool`\n  - Checks if a code is valid and not expired\n\n- `Initiate(code: str) -> bool`\n  - Activates a verification code\n  - Returns True if successful\n\n- `RemoveData(email: str) -> bool`\n  - Removes all codes for an email address\n\n### EmailService\n\n- `send_verification_code(recipient_email: str, code: str) -> bool`\n  - Sends verification code via email\n\n- `RedXSubEmail(recipient_email: str, expiration_time: str, custom_message: str = \"\") -> bool`\n  - Sends subscription confirmation email\n\n### SubscriptionService\n\n- `create_subscription(email: str, plan_type: str, duration_days: int, custom_message: str = \"\") -> Dict`\n  - Creates a new subscription\n  - Returns subscription details or error message\n\n- `check_subscription(email: str) -> Dict`\n  - Checks subscription status\n  - Returns subscription details or {\"active\": False}\n\n- `resign_subscription(email: str) -> bool`\n  - Cancels active subscription\n\n## Security Features\n\n- Secure code generation with checksums\n- Automatic code expiration handling\n- Rate limiting on API endpoints\n- Email verification\n- Secure database storage with PostgreSQL\n- Payment verification integration\n- Subscription expiration management\n\n## Best Practices\n\n1. Always verify payment completion before generating codes or creating subscriptions\n2. Use environment variables for sensitive data\n3. Implement proper error handling\n4. Monitor rate limits\n5. Regular cleanup of expired codes\n6. Keep subscriptions updated\n7. Use secure email configuration\n\n## Support\n\nFor issues and feature requests, please visit our GitHub repository: https://github.com/redxdev/redxauthcodes\n\n## License\n\nMIT License - See LICENSE file for details\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A comprehensive authentication and verification API platform providing secure, scalable identity management",
    "version": "1.0.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/redxdev/redxauthcodes/issues",
        "Documentation": "https://github.com/redxdev/redxauthcodes/blob/main/README.md",
        "Homepage": "https://github.com/redxdev/redxauthcodes",
        "Repository": "https://github.com/redxdev/redxauthcodes.git"
    },
    "split_keywords": [
        "authentication",
        " verification",
        " email",
        " notification",
        " security",
        " subscription"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "73cf175f2614d3a7c1fe056c5f09c70ce0a287e859e3ef869a5c6ec28440faff",
                "md5": "6623f5e12ee5a614ac7a9b8db40356c3",
                "sha256": "07ab5fbb7e9f202ca95242834530758bf1dc2ab2faec87aa4c207a83aeda98cd"
            },
            "downloads": -1,
            "filename": "RedXAuthCodes-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6623f5e12ee5a614ac7a9b8db40356c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 34690,
            "upload_time": "2025-01-29T00:01:14",
            "upload_time_iso_8601": "2025-01-29T00:01:14.746225Z",
            "url": "https://files.pythonhosted.org/packages/73/cf/175f2614d3a7c1fe056c5f09c70ce0a287e859e3ef869a5c6ec28440faff/RedXAuthCodes-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-29 00:01:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "redxdev",
    "github_project": "redxauthcodes",
    "github_not_found": true,
    "lcname": "redxauthcodes"
}
        
Elapsed time: 0.51024s