2a9ebe24: Implement auth endpoints (register/login/JWT) with SQLAlchemy

This commit is contained in:
OpenClaw Agent
2026-04-16 12:51:02 +00:00
parent ef5b32143a
commit 135d4111bb
12 changed files with 417 additions and 8 deletions

32
app/models/user.py Normal file
View File

@@ -0,0 +1,32 @@
"""User SQLAlchemy model."""
from datetime import datetime
from typing import Optional
from sqlalchemy import DateTime, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql import func
from app.db.database import Base
class User(Base):
"""User model for authentication and profile information."""
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
username: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
avatar_url: Mapped[Optional[str]] = mapped_column(
String(500), default="/static/default-avatar.png"
)
bio: Mapped[Optional[str]] = mapped_column(Text, default="")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
nullable=False,
)
def __repr__(self) -> str:
return f"<User(id={self.id}, username='{self.username}')>"