feat: add user authentication system

- User model (users table) with bcrypt password hashing
- JWT-based login API (POST /api/auth/login, GET /api/auth/me)
- Default admin account (admin/admin123) auto-created on startup
- Login page with centered dark-themed login card
- Route guards + Axios interceptors for token management
- Login page renders without sidebar (standalone layout)
- Gunicorn --preload to avoid worker DDL race condition
This commit is contained in:
2026-06-14 23:22:53 +08:00
parent 521cf0269c
commit cd41e59afc
14 changed files with 430 additions and 11 deletions
+3 -1
View File
@@ -5,5 +5,7 @@ from app.models.task import ScheduledTask # noqa: F401
from app.models.execution import TaskExecution # noqa: F401
from app.models.notification import Alert, AlertRule, NotificationChannel # noqa: F401
from app.models.system_config import SystemConfig # noqa: F401
from app.models.user import User # noqa: F401
__all__ = ["Agent", "ScheduledTask", "TaskExecution", "NotificationChannel", "AlertRule", "Alert", "SystemConfig"]
__all__ = ["Agent", "ScheduledTask", "TaskExecution", "NotificationChannel",
"AlertRule", "Alert", "SystemConfig", "User"]
+25
View File
@@ -0,0 +1,25 @@
"""SQLAlchemy models — User (dashboard login)."""
from datetime import datetime
from sqlalchemy import Boolean, DateTime, String, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class User(Base):
"""Dashboard user for login authentication."""
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
username: Mapped[str] = mapped_column(String(64), unique=True, nullable=False, comment="登录用户名")
password_hash: Mapped[str] = mapped_column(String(256), nullable=False, comment="bcrypt 密码哈希")
display_name: Mapped[str] = mapped_column(String(128), default="", comment="显示名称")
email: Mapped[str] = mapped_column(String(128), default="", comment="邮箱")
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
def __repr__(self) -> str:
return f"<User {self.username}>"