diff --git a/api/app/controllers/auth_controller.py b/api/app/controllers/auth_controller.py index a6960096..708cbaa2 100644 --- a/api/app/controllers/auth_controller.py +++ b/api/app/controllers/auth_controller.py @@ -61,6 +61,7 @@ async def login_for_access_token( user = auth_service.register_user_with_invite( db=db, email=form_data.email, + username=form_data.username, password=form_data.password, invite_token=form_data.invite, workspace_id=invite_info.workspace_id diff --git a/api/app/schemas/token_schema.py b/api/app/schemas/token_schema.py index 310e98a0..b10a3a14 100644 --- a/api/app/schemas/token_schema.py +++ b/api/app/schemas/token_schema.py @@ -26,5 +26,6 @@ class RefreshTokenRequest(BaseModel): class TokenRequest(BaseModel): email: EmailStr password: str - invite: Optional[str] = None + invite: Optional[str] = None, + username: Optional[str] = None diff --git a/api/app/services/auth_service.py b/api/app/services/auth_service.py index 877d8d5c..03e1ebc0 100644 --- a/api/app/services/auth_service.py +++ b/api/app/services/auth_service.py @@ -129,7 +129,8 @@ def register_user_with_invite( email: str, password: str, invite_token: str, - workspace_id: str + workspace_id: str, + username: Optional[str] = None, ) -> User: """ 使用邀请码注册新用户并加入工作空间 @@ -139,6 +140,7 @@ def register_user_with_invite( :param password: 用户密码 :param invite_token: 邀请令牌 :param workspace_id: 工作空间ID + :param username: 用户名 :return: 创建的用户对象 """ from app.schemas.user_schema import UserCreate @@ -154,7 +156,7 @@ def register_user_with_invite( user_create = UserCreate( email=email, password=password, - username=email.split('@')[0] + username=email.split('@')[0] if not username else username ) user = user_service.create_user(db=db, user=user_create) logger.info(f"用户创建成功: {user.email} (ID: {user.id})")