
This commit includes: - User registration and authentication API with JWT - Password reset functionality - Role-based access control system - Database models and migrations with SQLAlchemy and Alembic - API documentation in README generated with BackendIM... (backend.im)
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from pydantic import BaseModel, EmailStr, Field, validator
|
|
|
|
|
|
class PasswordReset(BaseModel):
|
|
email: EmailStr
|
|
|
|
|
|
class PasswordResetConfirm(BaseModel):
|
|
token: str
|
|
password: str = Field(..., min_length=8)
|
|
password_confirm: str
|
|
|
|
@validator("password")
|
|
def password_strength(cls, v):
|
|
"""Validate password strength."""
|
|
if len(v) < 8:
|
|
raise ValueError("Password must be at least 8 characters long")
|
|
if not any(char.isdigit() for char in v):
|
|
raise ValueError("Password must contain at least one digit")
|
|
if not any(char.isupper() for char in v):
|
|
raise ValueError("Password must contain at least one uppercase letter")
|
|
if not any(char.islower() for char in v):
|
|
raise ValueError("Password must contain at least one lowercase letter")
|
|
return v
|
|
|
|
@validator("password_confirm")
|
|
def passwords_match(cls, v, values, **kwargs):
|
|
"""Check that passwords match."""
|
|
if "password" in values and v != values["password"]:
|
|
raise ValueError("Passwords do not match")
|
|
return v |