功能: - 通知提醒系统: 还款日提醒、逾期提醒、系统消息横幅、登录时通知 - 通知中心UI: 铃铛图标 + 下拉列表 + 未读徽章 - 定时任务: APScheduler 每小时检查即将到期的还款 - 邮件通知: SMTP 发送还款提醒和安全警告 - 异常登录通知: 3/5/10次失败触发网页和邮件通知 安全: - 登录安全告警: 异常登录次数达到阈值时发送通知 - 密码重置链接: 一次性使用, 5分钟有效期 - 登录频率限制: IP级和账户级限制 技术: - 后端: FastAPI + SQLAlchemy + PostgreSQL - 前端: 纯 HTML/CSS/JS - 部署: Docker Compose (新增 build 配置)
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from app.models.models import Notification, NotificationType, User
|
|
|
|
|
|
async def create_notification(
|
|
db: AsyncSession,
|
|
user_id: int,
|
|
title: str,
|
|
message: str,
|
|
notification_type: str = NotificationType.SYSTEM.value,
|
|
related_debt_id: int | None = None,
|
|
related_plan_id: int | None = None,
|
|
) -> Notification:
|
|
n = Notification(
|
|
user_id=user_id,
|
|
title=title,
|
|
message=message,
|
|
type=notification_type,
|
|
related_debt_id=related_debt_id,
|
|
related_plan_id=related_plan_id,
|
|
)
|
|
db.add(n)
|
|
return n
|
|
|
|
|
|
async def create_system_broadcast(
|
|
db: AsyncSession,
|
|
title: str,
|
|
message: str,
|
|
) -> int:
|
|
users = await db.execute(select(User).where(User.status == "active"))
|
|
count = 0
|
|
for user in users.scalars().all():
|
|
db.add(Notification(
|
|
user_id=user.id, title=title, message=message,
|
|
type=NotificationType.SYSTEM.value,
|
|
))
|
|
count += 1
|
|
await db.commit()
|
|
return count
|