[feat]:[FL-172][用户管理页面新增用户时邮箱放最后,且不要必填]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
chengkai3
2026-06-18 00:34:03 +08:00
parent e37ecac9af
commit 6519fee729
5 changed files with 35 additions and 21 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ class User(Base):
primary_key=True,
default=lambda: uuid4().hex,
)
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
email: Mapped[str | None] = mapped_column(String(255), unique=True, index=True, nullable=True)
username: Mapped[str] = mapped_column(
settings.user_username_column,
String(64),
+1 -1
View File
@@ -36,7 +36,7 @@ class UserPasswordResetRequest(BaseModel):
class UserCreateRequest(BaseModel):
user_id: str = Field(min_length=3, max_length=64)
email: str
email: str | None = None
username: str = Field(min_length=3, max_length=64)
password: str = Field(min_length=8, max_length=128)
+7 -4
View File
@@ -95,17 +95,20 @@ def create_user(
) -> UserPublic | None:
user_id = payload.user_id.strip()
# Build conditions for duplicate check
conditions = [User.id == user_id, User.username == payload.username]
if payload.email:
conditions.append(User.email == payload.email.lower())
duplicate = db.scalar(
select(User.id).where(
(User.id == user_id) | (User.email == payload.email.lower()) | (User.username == payload.username)
)
select(User.id).where(or_(*conditions))
)
if duplicate:
return None
user = User(
id=user_id,
email=payload.email.lower(),
email=payload.email.lower() if payload.email else None,
username=payload.username,
password_hash=hash_password(payload.password),
status="ENABLED",