add user messages count action (#76)

* remove fastapi users dependency

* add user service to chatbot service

* add user save on bot info command

* add user model to admin

* fix tests
This commit is contained in:
Dmitry Afanasyev
2024-01-07 02:14:44 +03:00
committed by GitHub
parent fd9d38b5f0
commit 1e79c981c2
19 changed files with 811 additions and 798 deletions

View File

@@ -5,14 +5,15 @@ Revises: 0001_create_chatgpt_table
Create Date: 2023-11-28 00:58:01.984654
"""
import hashlib
from datetime import datetime
import fastapi_users_db_sqlalchemy
import sqlalchemy as sa
from alembic import op
from sqlalchemy import TIMESTAMP
from sqlalchemy.dialects.sqlite import insert
from core.auth.models.users import User
from core.auth.utils import create_password_hash
from infra.database.deps import get_sync_session
from settings.config import settings
@@ -28,12 +29,15 @@ def upgrade() -> None:
op.create_table(
"users",
sa.Column("id", sa.INTEGER(), nullable=False),
sa.Column("email", sa.VARCHAR(length=320), nullable=True),
sa.Column("email", sa.VARCHAR(length=255), nullable=True),
sa.Column("username", sa.VARCHAR(length=32), nullable=False),
sa.Column("first_name", sa.VARCHAR(length=32), nullable=True),
sa.Column("last_name", sa.VARCHAR(length=32), nullable=True),
sa.Column("hashed_password", sa.String(length=1024), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False),
sa.Column("is_superuser", sa.Boolean(), nullable=False),
sa.Column("is_verified", sa.Boolean(), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False, default=True),
sa.Column("is_superuser", sa.Boolean(), nullable=False, default=False),
sa.Column("ban_reason", sa.String(length=1024), nullable=True),
sa.Column("created_at", TIMESTAMP(timezone=True), nullable=False, default=datetime.now),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("email"),
)
@@ -41,8 +45,8 @@ def upgrade() -> None:
op.create_table(
"access_token",
sa.Column("user_id", sa.INTEGER(), nullable=False),
sa.Column("token", sa.String(length=43), nullable=False),
sa.Column("created_at", fastapi_users_db_sqlalchemy.generics.TIMESTAMPAware(timezone=True), nullable=False),
sa.Column("token", sa.String(length=42), nullable=False),
sa.Column("created_at", TIMESTAMP(timezone=True), nullable=False, default=datetime.now),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="cascade"),
sa.PrimaryKeyConstraint("token"),
)
@@ -53,7 +57,7 @@ def upgrade() -> None:
if not all([username, password, salt]):
return
with get_sync_session() as session:
hashed_password = hashlib.sha256((password.get_secret_value() + salt.get_secret_value()).encode()).hexdigest()
hashed_password = create_password_hash(password.get_secret_value())
query = insert(User).values({"username": username, "hashed_password": hashed_password})
session.execute(query)
session.commit()