feat(admin-invites): show registered usernames per invite code, track invited_by_code_id on User

This commit is contained in:
2026-07-06 08:37:49 +08:00
parent 293a021500
commit 755409f386
3 changed files with 7 additions and 1 deletions

View File

@@ -17,12 +17,14 @@ class User(Base):
username = Column(String(64), unique=True, nullable=False, index=True)
password_hash = Column(String(128), nullable=False)
is_admin = Column(Boolean, nullable=False, default=False)
invited_by_code_id = Column(Integer, ForeignKey("invite_codes.id", ondelete="SET NULL"), nullable=True)
showcase_mode = Column(String(16), nullable=False, default="profile")
created_at = Column(DateTime, default=_utcnow)
profiles = relationship("Profile", back_populates="user", cascade="all, delete-orphan")
sessions = relationship("UserSession", back_populates="user", cascade="all, delete-orphan")
invite_codes = relationship("InviteCode", back_populates="creator", cascade="all, delete-orphan")
invited_by_code = relationship("InviteCode", foreign_keys=[invited_by_code_id])
class InviteCode(Base):
@@ -37,6 +39,7 @@ class InviteCode(Base):
created_at = Column(DateTime, default=_utcnow)
creator = relationship("User", back_populates="invite_codes")
registered_users = relationship("User", back_populates="invited_by_code", foreign_keys="User.invited_by_code_id")
class UserSession(Base):

View File

@@ -153,7 +153,7 @@ def register_submit(
"register.html", {"request": request, "error": "用户名已存在"}, status_code=400
)
# Create user
new_user = User(username=username, password_hash=hash_password(password))
new_user = User(username=username, password_hash=hash_password(password), invited_by_code_id=code_obj.id)
db.add(new_user)
db.flush()
# Update invite code usage

View File

@@ -61,6 +61,9 @@
{% else %}
<span class="badge">永不过期</span>
{% endif %}
{% if c.registered_users %}
<span class="badge" style="background:#e8f5e9">注册用户: {{ c.registered_users|map(attribute='username')|join(', ') }}</span>
{% endif %}
</div>
<form method="post" action="/admin/invites/{{ c.id }}/edit" class="admin-invite-form" id="edit-form-{{ c.id }}">
<div class="aif-field">