mirror of
https://github.com/lorsanstand/Aether.git
synced 2026-06-19 12:05:16 +03:00
Add docker
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
*.so
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
*.log
|
||||
.git
|
||||
.gitignore
|
||||
.env
|
||||
.venv
|
||||
venv/
|
||||
ENV/
|
||||
env/
|
||||
.pytest_cache
|
||||
.coverage
|
||||
htmlcov/
|
||||
.mypy_cache
|
||||
.ruff_cache
|
||||
@@ -0,0 +1,18 @@
|
||||
FROM python:3.13.7-bookworm
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip install --no-cache-dir poetry
|
||||
|
||||
COPY pyproject.toml poetry.lock ./
|
||||
|
||||
RUN poetry config virtualenvs.create false && \
|
||||
poetry install --no-interaction --no-ansi --no-root
|
||||
|
||||
COPY app/ ./app
|
||||
COPY alembic.ini .
|
||||
COPY scripts ./scripts
|
||||
|
||||
RUN chmod +x /app/scripts/prestart.sh
|
||||
|
||||
CMD ["python", "-m", "app.main"]
|
||||
@@ -98,9 +98,9 @@ async def change_password(
|
||||
|
||||
@router.post("/password/reset")
|
||||
async def send_reset_password_email(
|
||||
username: str
|
||||
username_email: str
|
||||
) -> Dict:
|
||||
await UserService.send_reset_password_email(username)
|
||||
await UserService.send_reset_password_email(username_email)
|
||||
return {"status": True, "message": "Successfully send email reset password"}
|
||||
|
||||
@router.post("/password/reset/{token}")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import ForeignKey
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class MessageModel(Base):
|
||||
__tablename__ = "message"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
sender_id: Mapped[int] = mapped_column(ForeignKey("user.id", ondelete="CASCADE"), index=True)
|
||||
recipient_id: Mapped[int] = mapped_column(ForeignKey("user.id", ondelete="CASCADE"), index=True)
|
||||
content: Mapped[str] = mapped_column()
|
||||
@@ -9,10 +9,14 @@ class Settings(BaseSettings):
|
||||
MODE: Literal["DEV", "TEST", "PROD"]
|
||||
LOG_LEVEL: Literal["ERROR", "WARNING", "INFO", "DEBUG"]
|
||||
|
||||
HOST: str
|
||||
PORT: int
|
||||
BACKEND_HOST: str
|
||||
BACKEND_PORT: int
|
||||
WORKERS: int
|
||||
URL: str
|
||||
FRONTEND_URL: str
|
||||
|
||||
FIRST_SUPER_USER_EMAIL: str
|
||||
FIRST_SUPER_USER_PASS: str
|
||||
FIRST_SUPER_USER_USERNAME: str
|
||||
|
||||
CORS_ORIGINS: List[str] = ["http://localhost:5500", "http://127.0.0.1:5500", "http://localhost:8080", "http://127.0.0.1:8080", "null"]
|
||||
CORS_HEADERS: List[str] = ["*"]
|
||||
@@ -62,7 +66,7 @@ class Settings(BaseSettings):
|
||||
def RABBITMQ_URL(self) -> str:
|
||||
return f"amqp://{self.RMQ_USER}:{self.RMQ_PASS}@{self.RMQ_HOST}:{self.RMQ_PORT}//"
|
||||
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="allow")
|
||||
model_config = SettingsConfigDict(env_file="../.env", extra="allow")
|
||||
|
||||
|
||||
settings: Settings = Settings()
|
||||
+9
-9
@@ -29,6 +29,11 @@ async def lifespan(app: FastAPI):
|
||||
api_router = APIRouter(prefix="/api/v1")
|
||||
api_router.include_router(user_router)
|
||||
api_router.include_router(auth_router)
|
||||
|
||||
@api_router.get("/health")
|
||||
async def test_health():
|
||||
return {"status": True}
|
||||
|
||||
app = FastAPI(
|
||||
title=settings.COMPANY_NAME,
|
||||
description="## Backend messenger aether",
|
||||
@@ -82,24 +87,19 @@ async def log_requests(request: Request, call_next):
|
||||
raise
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def test_health():
|
||||
return {"status": True}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if settings.MODE == "PROD":
|
||||
UVICORN_PARAMS = dict(
|
||||
host=settings.HOST,
|
||||
port=settings.PORT,
|
||||
host=settings.BACKEND_HOST,
|
||||
port=settings.BACKEND_PORT,
|
||||
reload=False,
|
||||
workers=settings.WORKERS,
|
||||
access_log=False
|
||||
)
|
||||
else:
|
||||
UVICORN_PARAMS = dict(
|
||||
host=settings.HOST,
|
||||
port=settings.PORT,
|
||||
host=settings.BACKEND_HOST,
|
||||
port=settings.BACKEND_PORT,
|
||||
reload=True,
|
||||
access_log=False
|
||||
)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import asyncio
|
||||
|
||||
from app.core.database import async_session_maker
|
||||
from app.core.config import settings
|
||||
from app.users.schemas import UserCreateDB
|
||||
from app.users.dao import UserDAO
|
||||
from app.utils.hash_password import hash_password
|
||||
|
||||
|
||||
async def init() -> None:
|
||||
async with async_session_maker() as session:
|
||||
super_user = await UserDAO.find_one_or_none(session, email=settings.FIRST_SUPER_USER_EMAIL)
|
||||
|
||||
if super_user is not None:
|
||||
return
|
||||
|
||||
await UserDAO.add(
|
||||
session,
|
||||
obj_in=UserCreateDB(
|
||||
email=settings.FIRST_SUPER_USER_EMAIL,
|
||||
username=settings.FIRST_SUPER_USER_USERNAME,
|
||||
display_name="Admin",
|
||||
hashed_password=hash_password(settings.FIRST_SUPER_USER_PASS),
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
is_superuser=True
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
asyncio.run(init())
|
||||
@@ -7,7 +7,7 @@ from app.users.schemas import User, UserUpdate
|
||||
from app.users.service import UserService
|
||||
from app.auth.service import AuthService
|
||||
from app.users.models import UserModel
|
||||
from app.auth.dependencies import get_current_verified_user, get_current_superuser
|
||||
from app.auth.dependencies import get_current_verified_user, get_current_superuser, get_current_user
|
||||
|
||||
router = APIRouter(prefix="/users", tags=["User"])
|
||||
|
||||
@@ -15,7 +15,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/me")
|
||||
async def get_current_user(user: UserModel = Depends(get_current_verified_user)) -> User:
|
||||
async def get_current_user(user: UserModel = Depends(get_current_user)) -> User:
|
||||
log.debug("Getting current user profile", extra={"user_id": str(user.id)})
|
||||
return user
|
||||
|
||||
|
||||
@@ -5,11 +5,10 @@ from typing import List
|
||||
|
||||
from fastapi import HTTPException, status, UploadFile
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm.sync import update
|
||||
|
||||
from app.utils.hash_password import hash_password, verify_password
|
||||
from app.services.redis_service import EmailTokenStorage, ChangePasswordTokenStorage
|
||||
from app.core.S3_client import s3_client
|
||||
from app.utils.S3_client import s3_client
|
||||
from app.core.exceptions import InvalidTokenException, TokenExpiredException, UserNotFoundException
|
||||
from app.users.models import UserModel
|
||||
from app.users.dao import UserDAO
|
||||
@@ -66,7 +65,7 @@ class UserService:
|
||||
@classmethod
|
||||
async def send_verify_email(cls, user: UserModel):
|
||||
token = cls._create_uuid_token()
|
||||
url = f"{settings.URL}/verify-email/{token}"
|
||||
url = f"{settings.FRONTEND_URL}/verify-email/{token}"
|
||||
email_token_expires = timedelta(minutes=settings.EMAIL_TOKEN_EXPIRE_MINUTES)
|
||||
|
||||
await EmailTokenStorage.save_token(
|
||||
@@ -180,15 +179,21 @@ class UserService:
|
||||
|
||||
|
||||
@classmethod
|
||||
async def send_reset_password_email(cls, username: str):
|
||||
async def send_reset_password_email(cls, username_email: str):
|
||||
async with async_session_maker() as session:
|
||||
user = await UserDAO.find_one_or_none(session, username=username)
|
||||
user = await UserDAO.find_one_or_none(
|
||||
session,
|
||||
or_(
|
||||
UserModel.email==username_email,
|
||||
UserModel.username==username_email
|
||||
)
|
||||
)
|
||||
|
||||
if user is None:
|
||||
raise UserNotFoundException
|
||||
|
||||
token = cls._create_uuid_token()
|
||||
url = f"{settings.URL}/reset-password/{token}"
|
||||
url = f"{settings.FRONTEND_URL}/reset-password/{token}"
|
||||
token_expires = timedelta(minutes=settings.EMAIL_TOKEN_EXPIRE_MINUTES)
|
||||
|
||||
await ChangePasswordTokenStorage.save_token(
|
||||
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
alembic upgrade head
|
||||
|
||||
python -m app.pre_restart
|
||||
Reference in New Issue
Block a user