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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file myfy_user-0.1.2a94.tar.gz.
File metadata
- Download URL: myfy_user-0.1.2a94.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec808ea9fca57217c6b7eb2871639b638964965ba61c9c28531da79d58febf5e
|
|
| MD5 |
a522115890ce13235fb899b7ad87ba30
|
|
| BLAKE2b-256 |
0bc425241114d630d8a5bdb0c55fa5c804ae2e689b7e5b78980e74b5075b79fe
|
Provenance
The following attestation bundles were made for myfy_user-0.1.2a94.tar.gz:
Publisher:
publish.yml on psincraian/myfy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
myfy_user-0.1.2a94.tar.gz -
Subject digest:
ec808ea9fca57217c6b7eb2871639b638964965ba61c9c28531da79d58febf5e - Sigstore transparency entry: 813981248
- Sigstore integration time:
-
Permalink:
psincraian/myfy@f8f5d874325bdb62aa606f869ed73ae8947876b8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/psincraian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8f5d874325bdb62aa606f869ed73ae8947876b8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file myfy_user-0.1.2a94-py3-none-any.whl.
File metadata
- Download URL: myfy_user-0.1.2a94-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96d39ec3009441ee7ee2b46da435050fefd867658620f01381810110930e0407
|
|
| MD5 |
8cb8af4d12cb16cd7e79b43fed66d3db
|
|
| BLAKE2b-256 |
b47714785de4d0f432eff13f12225703515544198fe8c87982ae88bc146c7719
|
Provenance
The following attestation bundles were made for myfy_user-0.1.2a94-py3-none-any.whl:
Publisher:
publish.yml on psincraian/myfy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
myfy_user-0.1.2a94-py3-none-any.whl -
Subject digest:
96d39ec3009441ee7ee2b46da435050fefd867658620f01381810110930e0407 - Sigstore transparency entry: 813981249
- Sigstore integration time:
-
Permalink:
psincraian/myfy@f8f5d874325bdb62aa606f869ed73ae8947876b8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/psincraian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8f5d874325bdb62aa606f869ed73ae8947876b8 -
Trigger Event:
push
-
Statement type: