Skip to content

Commit 7960a92

Browse files
committed
fix(auth): restore local registration flow
1 parent 2e0cced commit 7960a92

32 files changed

Lines changed: 3780 additions & 1425 deletions

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
backend/scripts/*.sh text eol=lf

‎backend/app/api/v1/__init__.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from app.api.v1.rag import router as rag_router
1919
from app.api.v1.system import router as system_router
2020
from app.api.v1.user import router as user_router
21-
from app.api.v1.verification import router as verification_router
2221

2322
# 创建v1 API路由器
2423
api_router = APIRouter(prefix="/api/v1")
@@ -33,7 +32,6 @@
3332
api_router.include_router(rag_router)
3433
api_router.include_router(agent_router)
3534
api_router.include_router(system_router)
36-
api_router.include_router(verification_router)
3735
api_router.include_router(prompts_router)
3836
api_router.include_router(user_router)
3937
api_router.include_router(kb_permissions_router)
@@ -51,7 +49,6 @@
5149
"rag_router",
5250
"agent_router",
5351
"system_router",
54-
"verification_router",
5552
"prompts_router",
5653
"user_router",
5754
"kb_permissions_router",

‎backend/app/api/v1/auth.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ def register(
5555
UserResponse: 创建的用户信息
5656
5757
Raises:
58-
HTTPException 400: 用户名或邮箱已存在
58+
HTTPException 400: 用户名已存在
5959
"""
6060
auth_service = AuthService(db)
6161

6262
try:
6363
user = auth_service.register(
6464
username=user_data.username,
6565
password=user_data.password,
66-
email=user_data.email,
6766
)
6867
return UserResponse.model_validate(user)
6968
except UserAlreadyExistsError as e:

‎backend/app/api/v1/verification.py‎

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎backend/app/models/__init__.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from app.models.system_prompt import SystemPrompt
1818
from app.models.user import User
1919
from app.models.user_quota import UserQuota
20-
from app.models.verification_code import VerificationCode
2120

2221
# 导出所有模型
2322
__all__ = [
@@ -35,7 +34,6 @@
3534
"UserQuota",
3635
"APIUsage",
3736
"LoginAttempt",
38-
"VerificationCode",
3937
"SystemPrompt",
4038
"KnowledgeBasePermission",
4139
"PermissionType",

‎backend/app/models/verification_code.py‎

Lines changed: 0 additions & 53 deletions
This file was deleted.

‎backend/app/repositories/user_repository.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
用户数据访问层(Repository)
33
44
封装用户相关的数据库操作,提供统一的数据访问接口。
5-
实现CRUD操作和用户名/邮箱唯一性检查。
5+
实现CRUD操作和用户字段唯一性检查。
66
"""
77

88
from datetime import datetime
@@ -55,7 +55,7 @@ def create(
5555
User: 创建的用户对象
5656
5757
Raises:
58-
IntegrityError: 用户名或邮箱已存在时抛出
58+
IntegrityError: 用户名或资料邮箱已存在时抛出
5959
"""
6060
user = User(
6161
username=username, password_hash=password_hash, email=email, avatar=avatar
@@ -140,7 +140,7 @@ def update(
140140
Optional[User]: 更新后的用户对象,用户不存在则返回None
141141
142142
Raises:
143-
IntegrityError: 用户名或邮箱已被其他用户使用时抛出
143+
IntegrityError: 用户名或资料邮箱已被其他用户使用时抛出
144144
"""
145145
user = self.get_by_id(user_id)
146146
if not user:

‎backend/app/schemas/auth.py‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,17 @@ class UserRegister(BaseModel):
3232
description="密码(至少8位,包含字母和数字)",
3333
examples=["Password123", "SecurePass456"],
3434
)
35-
email: Optional[str] = Field(
36-
default=None,
37-
description="邮箱地址(可选)",
38-
examples=["user@example.com", "john.doe@company.com"],
39-
)
40-
4135
model_config = {
4236
"json_schema_extra": {
4337
"examples": [
4438
{
4539
"username": "testuser",
4640
"password": "Password123",
47-
"email": "test@example.com",
48-
},
49-
{"username": "john_doe", "password": "SecurePass456"},
41+
}
5042
]
5143
}
5244
}
5345

54-
@field_validator("email")
55-
@classmethod
56-
def validate_email(cls, v: Optional[str]) -> Optional[str]:
57-
"""验证邮箱格式"""
58-
if v is None:
59-
return v
60-
email_pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
61-
if not re.match(email_pattern, v):
62-
raise ValueError("邮箱格式不正确")
63-
return v
64-
6546
@field_validator("password")
6647
@classmethod
6748
def validate_password_strength(cls, v: str) -> str:

‎backend/app/schemas/verification.py‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎backend/app/services/auth/auth_service.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AuthService:
3131
3232
使用方式:
3333
auth_service = AuthService(db)
34-
user = auth_service.register("username", "password123", "email@example.com")
34+
user = auth_service.register("username", "password123")
3535
tokens = auth_service.login("username", "password123", "127.0.0.1")
3636
"""
3737

@@ -48,9 +48,7 @@ def __init__(self, db: Session):
4848
self._password_service = PasswordService(db)
4949
self._lockout_service = LockoutService()
5050

51-
def register(
52-
self, username: str, password: str, email: Optional[str] = None
53-
) -> User:
51+
def register(self, username: str, password: str) -> User:
5452
"""
5553
用户注册
5654
@@ -59,15 +57,13 @@ def register(
5957
Args:
6058
username: 用户名(必须唯一)
6159
password: 明文密码(至少8位,包含字母和数字)
62-
email: 邮箱地址(可选,必须唯一)
63-
6460
Returns:
6561
User: 创建的用户对象
6662
6763
Raises:
68-
UserAlreadyExistsError: 用户名或邮箱已存在
64+
UserAlreadyExistsError: 用户名已存在
6965
"""
70-
return self._registration_service.register(username, password, email)
66+
return self._registration_service.register(username, password)
7167

7268
def login(self, username: str, password: str, ip_address: str = "0.0.0.0") -> dict:
7369
"""

0 commit comments

Comments
 (0)