Skip to main content

User management module for myfy framework

Project description

myfy-user

User management module for the myfy framework.

Features

  • Email/Password Authentication - Secure password hashing with argon2/bcrypt
  • OAuth Authentication - Built-in support for Google and GitHub
  • Session Management - Cookie-based sessions for web applications
  • JWT Tokens - API authentication with access/refresh tokens
  • Email Verification - Token-based email verification flow
  • Password Reset - Secure password reset via email
  • User Profiles - Customizable user profiles
  • CLI Tools - Admin commands for user management
  • Bundled Templates - DaisyUI-styled Jinja2 templates

Installation

pip install myfy-user

Or with all myfy modules:

pip install myfy[all]

Quick Start

from myfy.core import Application
from myfy.data import DataModule
from myfy.web import WebModule
from myfy.auth import AuthModule
from myfy.user import UserModule

# Create application
app = Application()

# Add required modules
app.add_module(DataModule())
app.add_module(WebModule())

# Add user module
user_module = UserModule(
    oauth_providers=["google", "github"],
    auto_create_tables=True,
)

# Integrate with AuthModule
app.add_module(AuthModule(
    authenticated_provider=user_module.get_authenticated_provider(),
))
app.add_module(user_module)

Custom User Model

Extend the BaseUser model to add custom fields:

from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
from myfy.user import BaseUser, UserModule

class User(BaseUser):
    __tablename__ = "users"

    # Custom fields
    full_name: Mapped[str | None] = mapped_column(String(255))
    phone: Mapped[str | None] = mapped_column(String(20))
    organization: Mapped[str | None] = mapped_column(String(100))

# Use custom model
user_module = UserModule(user_model=User)

Configuration

Configure via environment variables:

# Required
MYFY_USER_SECRET_KEY=your-secret-key

# OAuth (optional)
MYFY_USER_OAUTH_GOOGLE_CLIENT_ID=...
MYFY_USER_OAUTH_GOOGLE_CLIENT_SECRET=...
MYFY_USER_OAUTH_GITHUB_CLIENT_ID=...
MYFY_USER_OAUTH_GITHUB_CLIENT_SECRET=...

# Sessions
MYFY_USER_SESSION_LIFETIME=604800  # 7 days
MYFY_USER_SESSION_SECURE=true

# Password requirements
MYFY_USER_PASSWORD_MIN_LENGTH=8
MYFY_USER_PASSWORD_ALGORITHM=argon2  # or bcrypt

CLI Commands

# Initialize user templates for customization
myfy user init

# Create an admin user
myfy user create-admin -e admin@example.com

# List users
myfy user list
myfy user list --admins-only

# Reset a user's password
myfy user reset-password -e user@example.com

# Deactivate/activate users
myfy user deactivate -e user@example.com
myfy user activate -e user@example.com

# Verify email manually
myfy user verify-email -e user@example.com

Routes

The module provides the following routes:

Method Path Description
GET /login Login page
POST /login Login submission
POST /logout Logout
GET /register Registration page
POST /register Registration submission
GET /oauth/{provider} OAuth redirect
GET /oauth/{provider}/callback OAuth callback
GET /forgot-password Password reset request
POST /forgot-password Send reset email
GET /reset-password/{token} Password reset page
POST /reset-password/{token} Set new password
GET /verify-email/{token} Verify email
GET /profile User profile (protected)
POST /profile Update profile

Background Tasks

When used with myfy-tasks, the module provides background tasks:

from myfy.user import (
    send_verification_email,
    send_password_reset_email,
    send_welcome_email,
    cleanup_expired_tokens,
)

# Send verification email asynchronously
await send_verification_email.send(
    user_id=user.id,
    token=token.token,
    base_url="https://myapp.com",
)

# Cleanup old tokens (run daily via scheduler)
await cleanup_expired_tokens.send(days_old=7)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

myfy_user-0.1.2a90.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

myfy_user-0.1.2a90-py3-none-any.whl (56.1 kB view details)

Uploaded Python 3

File details

Details for the file myfy_user-0.1.2a90.tar.gz.

File metadata

  • Download URL: myfy_user-0.1.2a90.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for myfy_user-0.1.2a90.tar.gz
Algorithm Hash digest
SHA256 a88a154b3286dc3c0aa5fc42d676ac9c0152f52e83036e5e8c3237a3547f5b04
MD5 c8f80980f16ec39c2a0b0824d1f84e0f
BLAKE2b-256 914028cdacd31638493d955f32eaec5caaabf0ab6f127b13f9ea63cefcae65fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for myfy_user-0.1.2a90.tar.gz:

Publisher: publish.yml on psincraian/myfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file myfy_user-0.1.2a90-py3-none-any.whl.

File metadata

  • Download URL: myfy_user-0.1.2a90-py3-none-any.whl
  • Upload date:
  • Size: 56.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for myfy_user-0.1.2a90-py3-none-any.whl
Algorithm Hash digest
SHA256 0628fbb2be90c3c227dd433afaa026483ab106649a71bb2adca2e7a8a356f76b
MD5 509ac170e10607f49cdf0585d4d47099
BLAKE2b-256 b140f2b407a9e6010c4d50b9873c379f19457d9151261174b2b68ca2a9fb5ef4

See more details on using hashes here.

Provenance

The following attestation bundles were made for myfy_user-0.1.2a90-py3-none-any.whl:

Publisher: publish.yml on psincraian/myfy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page