setup profile edition
This commit is contained in:
51
app/bot/dialogs/flows/profile/handlers.py
Normal file
51
app/bot/dialogs/flows/profile/handlers.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import re
|
||||
|
||||
from aiogram.types import Message
|
||||
from aiogram_dialog import DialogManager
|
||||
from aiogram_dialog.widgets.input import ManagedTextInput
|
||||
|
||||
from app.infrastructure.database.crud import update_user
|
||||
|
||||
from .states import ProfileSG
|
||||
|
||||
|
||||
def name_type_factory(text: str):
|
||||
if not 2 < len(text) < 20:
|
||||
raise ValueError("Имя должно быть от 2 до 20 символов")
|
||||
|
||||
def phone_type_factory(text: str):
|
||||
if len(re.findall("\d", text)) < 11:
|
||||
raise ValueError("Телефон должен быть в формате \+79991112233")
|
||||
return text
|
||||
|
||||
async def on_error(
|
||||
message: Message,
|
||||
widget: ManagedTextInput,
|
||||
dialog_manager: DialogManager,
|
||||
error: ValueError,
|
||||
):
|
||||
await message.answer(error.args[0])
|
||||
|
||||
|
||||
async def update_user_name(
|
||||
message: Message,
|
||||
widget: ManagedTextInput,
|
||||
dialog_manager: DialogManager,
|
||||
text: str,
|
||||
):
|
||||
session = dialog_manager.middleware_data["session"]
|
||||
await update_user(session, message.from_user.id, fullname=text.strip())
|
||||
await dialog_manager.switch_to(ProfileSG.profile)
|
||||
|
||||
|
||||
async def update_user_phone(
|
||||
message: Message,
|
||||
widget: ManagedTextInput,
|
||||
dialog_manager: DialogManager,
|
||||
text: str,
|
||||
):
|
||||
session = dialog_manager.middleware_data["session"]
|
||||
print(text)
|
||||
text = ''.join(re.findall(r"\d", text))
|
||||
await update_user(session, message.from_user.id, phone=text)
|
||||
await dialog_manager.switch_to(ProfileSG.profile)
|
||||
Reference in New Issue
Block a user