feat: create new user with password
This commit is contained in:
@@ -6,9 +6,10 @@ from typing import Optional
|
||||
from sqlalchemy import func, insert, select
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.db.logic.keyring import create_password_key
|
||||
from api.db.tables.account import account_table
|
||||
from api.schemas.account.account import User
|
||||
from api.schemas.endpoints.account import all_user_adapter, AllUserResponse, UserUpdate
|
||||
from api.schemas.endpoints.account import all_user_adapter, AllUser, AllUserResponse, UserCreate, UserUpdate
|
||||
|
||||
|
||||
async def get_user_accaunt_page(connection: AsyncConnection, page, limit) -> Optional[AllUserResponse]:
|
||||
@@ -54,7 +55,7 @@ async def get_user_accaunt_page(connection: AsyncConnection, page, limit) -> Opt
|
||||
)
|
||||
|
||||
|
||||
async def get_user_by_id(connection: AsyncConnection, user_id: int) -> Optional[UserUpdate]:
|
||||
async def get_user_by_id(connection: AsyncConnection, user_id: int) -> Optional[AllUser]:
|
||||
"""
|
||||
Получает юзера по id.
|
||||
"""
|
||||
@@ -66,7 +67,7 @@ async def get_user_by_id(connection: AsyncConnection, user_id: int) -> Optional[
|
||||
if not user:
|
||||
return None
|
||||
|
||||
return UserUpdate.model_validate(user)
|
||||
return AllUser.model_validate(user)
|
||||
|
||||
|
||||
async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional[User]:
|
||||
@@ -102,7 +103,7 @@ async def update_user_by_id(connection: AsyncConnection, update_values, user) ->
|
||||
await connection.commit()
|
||||
|
||||
|
||||
async def create_user(connection: AsyncConnection, user: UserUpdate, creator_id: int) -> Optional[UserUpdate]:
|
||||
async def create_user(connection: AsyncConnection, user: UserCreate, creator_id: int) -> Optional[AllUser]:
|
||||
"""
|
||||
Создает нове поле в таблице account_table.
|
||||
"""
|
||||
@@ -112,7 +113,7 @@ async def create_user(connection: AsyncConnection, user: UserUpdate, creator_id:
|
||||
email=user.email,
|
||||
bind_tenant_id=user.bind_tenant_id,
|
||||
role=user.role.value,
|
||||
meta=user.meta,
|
||||
meta=user.meta or {},
|
||||
creator_id=creator_id,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
status=user.status.value,
|
||||
@@ -121,6 +122,7 @@ async def create_user(connection: AsyncConnection, user: UserUpdate, creator_id:
|
||||
res = await connection.execute(query)
|
||||
|
||||
await connection.commit()
|
||||
user = await get_user_by_id(connection, res.lastrowid)
|
||||
new_user = await get_user_by_id(connection, res.lastrowid)
|
||||
await create_password_key(connection, user.password, new_user.id)
|
||||
|
||||
return user
|
||||
return new_user
|
||||
|
Reference in New Issue
Block a user