🐛 fix: восстановить эндпоинты верификации и добавить уведомления жильцам
This commit is contained in:
parent
b1cda13c96
commit
3893f38532
1 changed files with 61 additions and 0 deletions
61
web/app.py
61
web/app.py
|
|
@ -249,6 +249,24 @@ async def api_approve_verification(req_id: int, username: str = Depends(get_curr
|
||||||
req.reviewed_at = datetime.utcnow()
|
req.reviewed_at = datetime.utcnow()
|
||||||
await session.execute(update(User).where(User.user_id == req.user_id).values(verified=True, apartment=req.apartment, verification_date=datetime.utcnow()))
|
await session.execute(update(User).where(User.user_id == req.user_id).values(verified=True, apartment=req.apartment, verification_date=datetime.utcnow()))
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
||||||
|
# Уведомляем пользователя
|
||||||
|
try:
|
||||||
|
proxy_url = config.get_proxy_url()
|
||||||
|
async with aiohttp.ClientSession() as http_session:
|
||||||
|
await http_session.post(
|
||||||
|
f"https://api.telegram.org/bot{config.BOT_TOKEN}/sendMessage",
|
||||||
|
json={
|
||||||
|
"chat_id": req.user_id,
|
||||||
|
"text": f"✅ <b>Ваша заявка на верификацию одобрена!</b>\n\nКвартира: {req.apartment}\nТеперь вам доступны все функции бота.",
|
||||||
|
"parse_mode": "HTML"
|
||||||
|
},
|
||||||
|
proxy=proxy_url,
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error notifying user {req.user_id}: {e}")
|
||||||
|
|
||||||
return JSONResponse({"success": True})
|
return JSONResponse({"success": True})
|
||||||
|
|
||||||
@app.post("/api/verification/{req_id}/reject")
|
@app.post("/api/verification/{req_id}/reject")
|
||||||
|
|
@ -261,6 +279,49 @@ async def api_reject_verification(req_id: int, username: str = Depends(get_curre
|
||||||
await session.commit()
|
await session.commit()
|
||||||
return JSONResponse({"success": True})
|
return JSONResponse({"success": True})
|
||||||
|
|
||||||
|
@app.post("/api/user/{user_id}/verify")
|
||||||
|
async def api_verify_user(user_id: int, username: str = Depends(get_current_admin)):
|
||||||
|
async with AsyncSessionLocal() as session:
|
||||||
|
user = (await session.execute(select(User).where(User.user_id == user_id))).scalar_one_or_none()
|
||||||
|
if not user:
|
||||||
|
return JSONResponse({"success": False, "error": "Пользователь не найден"})
|
||||||
|
|
||||||
|
user.verified = True
|
||||||
|
user.verification_date = datetime.utcnow()
|
||||||
|
await session.commit()
|
||||||
|
|
||||||
|
# Уведомляем пользователя через бот
|
||||||
|
try:
|
||||||
|
proxy_url = config.get_proxy_url()
|
||||||
|
async with aiohttp.ClientSession() as http_session:
|
||||||
|
await http_session.post(
|
||||||
|
f"https://api.telegram.org/bot{config.BOT_TOKEN}/sendMessage",
|
||||||
|
json={
|
||||||
|
"chat_id": user_id,
|
||||||
|
"text": "✅ <b>Верификация подтверждена!</b>\n\nТеперь у вас есть полный доступ ко всем функциям бота LKM37.",
|
||||||
|
"parse_mode": "HTML"
|
||||||
|
},
|
||||||
|
proxy=proxy_url,
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error notifying user {user_id}: {e}")
|
||||||
|
|
||||||
|
return JSONResponse({"success": True})
|
||||||
|
|
||||||
|
@app.post("/api/user/{user_id}/unverify")
|
||||||
|
async def api_unverify_user(user_id: int, username: str = Depends(get_current_admin)):
|
||||||
|
async with AsyncSessionLocal() as session:
|
||||||
|
user = (await session.execute(select(User).where(User.user_id == user_id))).scalar_one_or_none()
|
||||||
|
if not user:
|
||||||
|
return JSONResponse({"success": False, "error": "Пользователь не найден"})
|
||||||
|
|
||||||
|
user.verified = False
|
||||||
|
user.verification_date = None
|
||||||
|
await session.commit()
|
||||||
|
|
||||||
|
return JSONResponse({"success": True})
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# ТЕЛЕФОНЫ / ОБЪЯВЛЕНИЯ / ОПРОСЫ / СОБЫТИЯ / ГРАФИКИ
|
# ТЕЛЕФОНЫ / ОБЪЯВЛЕНИЯ / ОПРОСЫ / СОБЫТИЯ / ГРАФИКИ
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue