Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
plabel
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
project
plabel
Commits
a5e3136b
提交
a5e3136b
authored
5月 29, 2026
作者:
caifuming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cfm_问题21 用户注册功能 完成,问题2. 个人中心,退出功能完成
上级
58b7a2a7
显示空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
389 行增加
和
148 行删除
+389
-148
auth.py
backend/app/api/v1/auth.py
+48
-33
security.py
backend/app/core/security.py
+15
-6
data_item.py
backend/app/models/data_item.py
+5
-3
label.py
backend/app/models/label.py
+7
-5
label_set.py
backend/app/models/label_set.py
+5
-8
project.py
backend/app/models/project.py
+10
-6
project_member.py
backend/app/models/project_member.py
+8
-6
task.py
backend/app/models/task.py
+8
-6
base.py
backend/app/schemas/base.py
+25
-3
auth.ts
frontend/src/api/auth.ts
+7
-5
Header.vue
frontend/src/components/layout/Header.vue
+3
-3
user.ts
frontend/src/store/user.ts
+6
-11
Login.vue
frontend/src/views/auth/Login.vue
+8
-9
Register.vue
frontend/src/views/auth/Register.vue
+2
-2
Vue_8008.log
logs/Vue_8008.log
+0
-0
vue_8008.pid
logs/vue_8008.pid
+1
-1
后端需求清单.md
md/后端需求清单.md
+85
-2
start-services.sh
scripts/start-services.sh
+146
-39
没有找到文件。
backend/app/api/v1/auth.py
浏览文件 @
a5e3136b
...
...
@@ -21,6 +21,7 @@ from app.schemas.auth import (
TokenResponse
,
UserResponse
,
)
from
app.schemas.base
import
ApiResponse
from
app.services.auth_service
import
AuthService
router
=
APIRouter
(
prefix
=
"/auth"
,
tags
=
[
"Authentication"
])
...
...
@@ -38,11 +39,11 @@ def user_to_response(user: User) -> UserResponse:
)
@router.post
(
"/login"
,
response_model
=
LoginResponse
)
@router.post
(
"/login"
,
response_model
=
ApiResponse
[
LoginResponse
]
)
async
def
login
(
login_data
:
LoginRequest
,
db
:
AsyncSession
=
Depends
(
get_async_session
),
)
->
LoginResponse
:
)
->
ApiResponse
[
LoginResponse
]
:
"""
User login endpoint
...
...
@@ -53,12 +54,18 @@ async def login(
try
:
user
,
access_token
=
await
auth_service
.
login
(
login_data
)
return
LoginResponse
(
login_response
=
LoginResponse
(
access_token
=
access_token
,
token_type
=
"bearer"
,
expires_in
=
settings
.
access_token_expire_minutes
*
60
,
user
=
user_to_response
(
user
),
)
return
ApiResponse
(
code
=
200
,
message
=
"success"
,
data
=
login_response
)
except
AuthenticationError
as
e
:
raise
HTTPException
(
status_code
=
status
.
HTTP_401_UNAUTHORIZED
,
...
...
@@ -67,34 +74,26 @@ async def login(
)
@router.post
(
"/register"
,
response_model
=
LoginResponse
,
status_code
=
status
.
HTTP_201_CREATED
)
@router.post
(
"/register"
,
response_model
=
ApiResponse
[
UserResponse
]
,
status_code
=
status
.
HTTP_201_CREATED
)
async
def
register
(
register_data
:
RegisterRequest
,
db
:
AsyncSession
=
Depends
(
get_async_session
),
)
->
LoginResponse
:
)
->
ApiResponse
[
UserResponse
]
:
"""
User registration endpoint
Creates a new user account and returns access token
Creates a new user account.
IMPORTANT: Does NOT return access token - user must login manually after registration.
"""
auth_service
=
AuthService
(
db
)
try
:
user
=
await
auth_service
.
register
(
register_data
)
access_token
=
create_access_token
(
data
=
{
"sub"
:
str
(
user
.
id
),
"email"
:
user
.
email
,
"role"
:
user
.
role
,
}
)
return
LoginResponse
(
access_token
=
access_token
,
token_type
=
"bearer"
,
expires_in
=
settings
.
access_token_expire_minutes
*
60
,
user
=
user_to_response
(
user
),
return
ApiResponse
(
code
=
201
,
message
=
"注册成功,请使用账号密码登录"
,
data
=
user_to_response
(
user
)
)
except
ConflictError
as
e
:
raise
HTTPException
(
...
...
@@ -108,33 +107,41 @@ async def register(
)
@router.post
(
"/logout"
)
async
def
logout
(
current_user
:
User
=
Depends
(
get_current_user
))
->
dict
:
@router.post
(
"/logout"
,
response_model
=
ApiResponse
[
dict
]
)
async
def
logout
(
)
->
ApiResponse
[
dict
]
:
"""
User logout endpoint
Note: For JWT-based auth, logout is
typically handled client-side
by removing the token from storage
.
Note: For JWT-based auth, logout is
handled client-side by removing the token.
This endpoint is kept for consistency but does not require authentication
.
"""
return
{
"message"
:
"Successfully logged out"
}
return
ApiResponse
(
code
=
200
,
message
=
"Successfully logged out"
,
data
=
{}
)
@router.get
(
"/me"
,
response_model
=
UserResponse
)
@router.get
(
"/me"
,
response_model
=
ApiResponse
[
UserResponse
]
)
async
def
get_current_user_info
(
current_user
:
User
=
Depends
(
get_current_user
),
)
->
UserResponse
:
)
->
ApiResponse
[
UserResponse
]
:
"""
Get current authenticated user information
"""
return
user_to_response
(
current_user
)
return
ApiResponse
(
code
=
200
,
message
=
"success"
,
data
=
user_to_response
(
current_user
)
)
@router.put
(
"/me"
,
response_model
=
UserResponse
)
@router.put
(
"/me"
,
response_model
=
ApiResponse
[
UserResponse
]
)
async
def
update_current_user
(
user_data
:
dict
,
current_user
:
User
=
Depends
(
get_current_user
),
db
:
AsyncSession
=
Depends
(
get_async_session
),
)
->
UserResponse
:
)
->
ApiResponse
[
UserResponse
]
:
"""
Update current user's profile information
"""
...
...
@@ -147,15 +154,19 @@ async def update_current_user(
UserUpdate
(
**
{
k
:
v
for
k
,
v
in
user_data
.
items
()
if
k
in
[
"username"
,
"email"
,
"avatar_url"
]})
)
return
user_to_response
(
updated_user
)
return
ApiResponse
(
code
=
200
,
message
=
"success"
,
data
=
user_to_response
(
updated_user
)
)
@router.post
(
"/change-password"
)
@router.post
(
"/change-password"
,
response_model
=
ApiResponse
[
dict
]
)
async
def
change_password
(
password_data
:
ChangePasswordRequest
,
current_user
:
User
=
Depends
(
get_current_user
),
db
:
AsyncSession
=
Depends
(
get_async_session
),
)
->
dict
:
)
->
ApiResponse
[
dict
]
:
"""
Change current user's password
"""
...
...
@@ -169,7 +180,11 @@ async def change_password(
password_data
.
old_password
,
password_data
.
new_password
,
)
return
{
"message"
:
"Password updated successfully"
}
return
ApiResponse
(
code
=
200
,
message
=
"Password updated successfully"
,
data
=
{}
)
except
PermissionDeniedError
:
raise
HTTPException
(
status_code
=
status
.
HTTP_403_FORBIDDEN
,
...
...
backend/app/core/security.py
浏览文件 @
a5e3136b
...
...
@@ -5,23 +5,32 @@ Security utilities for authentication and authorization
from
datetime
import
datetime
,
timedelta
from
typing
import
Optional
import
bcrypt
from
jose
import
JWTError
,
jwt
from
passlib.context
import
CryptContext
from
app.core.config
import
settings
# Password hashing context
pwd_context
=
CryptContext
(
schemes
=
[
"bcrypt"
],
deprecated
=
"auto"
)
def
verify_password
(
plain_password
:
str
,
hashed_password
:
str
)
->
bool
:
"""Verify a plain password against a hashed password"""
return
pwd_context
.
verify
(
plain_password
,
hashed_password
)
try
:
password_bytes
=
plain_password
.
encode
(
'utf-8'
)
if
len
(
password_bytes
)
>
72
:
password_bytes
=
password_bytes
[:
72
]
hashed_bytes
=
hashed_password
.
encode
(
'utf-8'
)
return
bcrypt
.
checkpw
(
password_bytes
,
hashed_bytes
)
except
Exception
:
return
False
def
hash_password
(
password
:
str
)
->
str
:
"""Hash a password using bcrypt"""
return
pwd_context
.
hash
(
password
)
password_bytes
=
password
.
encode
(
'utf-8'
)
if
len
(
password_bytes
)
>
72
:
password_bytes
=
password_bytes
[:
72
]
salt
=
bcrypt
.
gensalt
(
rounds
=
12
)
hashed
=
bcrypt
.
hashpw
(
password_bytes
,
salt
)
return
hashed
.
decode
(
'utf-8'
)
def
create_access_token
(
...
...
backend/app/models/data_item.py
浏览文件 @
a5e3136b
...
...
@@ -2,10 +2,12 @@
DataItem model
"""
import
uuid
from
typing
import
TYPE_CHECKING
,
Optional
from
sqlalchemy
import
BigInteger
,
Float
,
ForeignKey
,
Integer
,
String
from
sqlalchemy
import
JSON
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
app.core.database
import
Base
...
...
@@ -20,9 +22,9 @@ class DataItem(Base):
__tablename__
=
"data_items"
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
task_id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
ForeignKey
(
"tasks.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid
.
uuid4
)
task_id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"tasks.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
)
name
:
Mapped
[
str
]
=
mapped_column
(
String
(
500
),
nullable
=
False
)
type
:
Mapped
[
str
]
=
mapped_column
(
String
(
20
),
nullable
=
False
,
index
=
True
)
...
...
backend/app/models/label.py
浏览文件 @
a5e3136b
...
...
@@ -2,10 +2,12 @@
Label model
"""
import
uuid
from
typing
import
TYPE_CHECKING
,
Optional
from
sqlalchemy
import
ForeignKey
,
Integer
,
String
from
sqlalchemy
import
ForeignKey
,
String
from
sqlalchemy
import
JSON
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
app.core.database
import
Base
...
...
@@ -19,15 +21,15 @@ class Label(Base):
__tablename__
=
"labels"
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
label_set_id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
ForeignKey
(
"label_sets.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid
.
uuid4
)
label_set_id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"label_sets.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
)
name
:
Mapped
[
str
]
=
mapped_column
(
String
(
100
),
nullable
=
False
)
color
:
Mapped
[
str
]
=
mapped_column
(
String
(
7
),
nullable
=
False
)
type
:
Mapped
[
str
]
=
mapped_column
(
String
(
30
),
nullable
=
False
,
index
=
True
)
shortcut
:
Mapped
[
Optional
[
str
]]
=
mapped_column
(
String
(
10
),
nullable
=
True
)
parent_id
:
Mapped
[
Optional
[
int
]]
=
mapped_column
(
Integer
,
ForeignKey
(
"labels.id"
),
nullable
=
True
)
parent_id
:
Mapped
[
Optional
[
uuid
.
UUID
]]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"labels.id"
),
nullable
=
True
)
attributes
:
Mapped
[
dict
]
=
mapped_column
(
JSON
,
default
=
list
)
label_set
:
Mapped
[
"LabelSet"
]
=
relationship
(
"LabelSet"
,
back_populates
=
"labels"
)
backend/app/models/label_set.py
浏览文件 @
a5e3136b
...
...
@@ -2,15 +2,16 @@
LabelSet model
"""
from
typing
import
TYPE_CHECKING
,
Optional
import
uuid
from
typing
import
TYPE_CHECKING
from
sqlalchemy
import
ForeignKey
,
Integer
,
String
from
sqlalchemy
import
String
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
app.core.database
import
Base
if
TYPE_CHECKING
:
from
app.models.project
import
Project
from
app.models.label
import
Label
...
...
@@ -19,11 +20,7 @@ class LabelSet(Base):
__tablename__
=
"label_sets"
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
project_id
:
Mapped
[
Optional
[
int
]]
=
mapped_column
(
Integer
,
ForeignKey
(
"projects.id"
,
ondelete
=
"CASCADE"
),
nullable
=
True
,
index
=
True
)
id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid
.
uuid4
)
name
:
Mapped
[
str
]
=
mapped_column
(
String
(
200
),
nullable
=
False
)
project
:
Mapped
[
Optional
[
"Project"
]]
=
relationship
(
"Project"
,
back_populates
=
"label_set"
)
labels
:
Mapped
[
list
[
"Label"
]]
=
relationship
(
"Label"
,
back_populates
=
"label_set"
,
cascade
=
"all, delete-orphan"
)
backend/app/models/project.py
浏览文件 @
a5e3136b
...
...
@@ -2,9 +2,11 @@
Project model
"""
import
uuid
from
typing
import
TYPE_CHECKING
,
Optional
from
sqlalchemy
import
ForeignKey
,
Integer
,
String
,
Text
from
sqlalchemy
import
ForeignKey
,
String
,
Text
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
app.core.database
import
Base
...
...
@@ -21,16 +23,18 @@ class Project(Base):
__tablename__
=
"projects"
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid
.
uuid4
)
name
:
Mapped
[
str
]
=
mapped_column
(
String
(
200
),
nullable
=
False
)
description
:
Mapped
[
Optional
[
str
]]
=
mapped_column
(
Text
,
nullable
=
True
)
status
:
Mapped
[
str
]
=
mapped_column
(
String
(
20
),
nullable
=
False
,
default
=
"active"
,
index
=
True
)
owner_id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
ForeignKey
(
"users.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
owner_id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
ForeignKey
(
"users.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
)
label_set_id
:
Mapped
[
Optional
[
uuid
.
UUID
]]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
ForeignKey
(
"label_sets.id"
,
ondelete
=
"SET NULL"
),
nullable
=
True
)
label_set_id
:
Mapped
[
Optional
[
int
]]
=
mapped_column
(
Integer
,
nullable
=
True
)
owner
:
Mapped
[
"User"
]
=
relationship
(
"User"
,
back_populates
=
"owned_projects"
)
label_set
:
Mapped
[
Optional
[
"LabelSet"
]]
=
relationship
(
"LabelSet"
,
foreign_keys
=
[
label_set_id
]
,
post_update
=
True
)
label_set
:
Mapped
[
Optional
[
"LabelSet"
]]
=
relationship
(
"LabelSet"
,
foreign_keys
=
[
label_set_id
])
tasks
:
Mapped
[
list
[
"Task"
]]
=
relationship
(
"Task"
,
back_populates
=
"project"
,
cascade
=
"all, delete-orphan"
)
members
:
Mapped
[
list
[
"ProjectMember"
]]
=
relationship
(
"ProjectMember"
,
back_populates
=
"project"
,
cascade
=
"all, delete-orphan"
)
backend/app/models/project_member.py
浏览文件 @
a5e3136b
...
...
@@ -2,9 +2,11 @@
ProjectMember model
"""
import
uuid
from
typing
import
TYPE_CHECKING
from
sqlalchemy
import
ForeignKey
,
Integer
,
String
from
sqlalchemy
import
ForeignKey
,
String
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
app.core.database
import
Base
...
...
@@ -19,12 +21,12 @@ class ProjectMember(Base):
__tablename__
=
"project_members"
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
project_id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
ForeignKey
(
"projects.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid
.
uuid4
)
project_id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"projects.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
)
user_id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
ForeignKey
(
"users.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
user_id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"users.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
)
role
:
Mapped
[
str
]
=
mapped_column
(
String
(
20
),
nullable
=
False
,
default
=
"member"
)
...
...
backend/app/models/task.py
浏览文件 @
a5e3136b
...
...
@@ -2,10 +2,12 @@
Task model
"""
import
uuid
from
typing
import
TYPE_CHECKING
,
Optional
from
sqlalchemy
import
ForeignKey
,
Integer
,
String
,
Text
from
sqlalchemy
import
JSON
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
app.core.database
import
Base
...
...
@@ -22,18 +24,18 @@ class Task(Base):
__tablename__
=
"tasks"
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
project_id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
ForeignKey
(
"projects.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid
.
uuid4
)
project_id
:
Mapped
[
uuid
.
UUID
]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"projects.id"
,
ondelete
=
"CASCADE"
),
nullable
=
False
,
index
=
True
)
name
:
Mapped
[
str
]
=
mapped_column
(
String
(
200
),
nullable
=
False
)
description
:
Mapped
[
Optional
[
str
]]
=
mapped_column
(
Text
,
nullable
=
True
)
data_type
:
Mapped
[
str
]
=
mapped_column
(
String
(
20
),
nullable
=
False
,
index
=
True
)
annotation_types
:
Mapped
[
list
]
=
mapped_column
(
JSON
,
default
=
list
)
status
:
Mapped
[
str
]
=
mapped_column
(
String
(
20
),
nullable
=
False
,
default
=
"pending"
,
index
=
True
)
assignee_id
:
Mapped
[
Optional
[
int
]]
=
mapped_column
(
Integer
,
ForeignKey
(
"users.id"
),
nullable
=
True
,
index
=
True
)
reviewer_id
:
Mapped
[
Optional
[
int
]]
=
mapped_column
(
Integer
,
ForeignKey
(
"users.id"
),
nullable
=
True
)
ai_model_id
:
Mapped
[
Optional
[
int
]]
=
mapped_column
(
Integer
,
ForeignKey
(
"ai_models.id"
),
nullable
=
True
)
assignee_id
:
Mapped
[
Optional
[
uuid
.
UUID
]]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"users.id"
),
nullable
=
True
,
index
=
True
)
reviewer_id
:
Mapped
[
Optional
[
uuid
.
UUID
]]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"users.id"
),
nullable
=
True
)
ai_model_id
:
Mapped
[
Optional
[
uuid
.
UUID
]]
=
mapped_column
(
UUID
(
as_uuid
=
True
)
,
ForeignKey
(
"ai_models.id"
),
nullable
=
True
)
progress
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
default
=
0
)
total_count
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
default
=
0
)
completed_count
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
default
=
0
)
...
...
backend/app/schemas/base.py
浏览文件 @
a5e3136b
...
...
@@ -3,7 +3,7 @@ Base Pydantic schemas
"""
from
datetime
import
datetime
from
typing
import
Any
,
Generic
,
TypeVar
from
typing
import
Any
,
Generic
,
TypeVar
,
Optional
from
pydantic
import
BaseModel
,
ConfigDict
,
Field
...
...
@@ -22,15 +22,37 @@ class PaginationSchema(BaseSchema):
total_pages
:
int
=
Field
(
ge
=
0
,
description
=
"Total number of pages"
)
class
ResponseSchema
(
BaseSchema
):
T
=
TypeVar
(
'T'
)
class
ApiResponse
(
BaseModel
,
Generic
[
T
]):
"""Standard API response wrapper"""
code
:
int
=
Field
(
default
=
200
,
description
=
"Response status code"
)
message
:
str
=
Field
(
default
=
"success"
,
description
=
"Response message"
)
data
:
Optional
[
T
]
=
Field
(
default
=
None
,
description
=
"Response data"
)
model_config
=
ConfigDict
(
from_attributes
=
True
)
class
ErrorResponse
(
BaseModel
):
"""Standard error response"""
code
:
int
=
Field
(
description
=
"Error code"
)
message
:
str
=
Field
(
description
=
"Error message"
)
errors
:
Optional
[
list
[
dict
]]
=
Field
(
default
=
None
,
description
=
"Detailed error list"
)
details
:
Optional
[
Any
]
=
Field
(
default
=
None
,
description
=
"Additional error details"
)
model_config
=
ConfigDict
(
from_attributes
=
True
)
class
ResponseSchema
(
BaseSchema
):
"""Standard API response wrapper (deprecated, use ApiResponse instead)"""
code
:
int
=
200
message
:
str
=
"success"
data
:
Any
=
None
class
ErrorResponseSchema
(
BaseSchema
):
"""Standard error response"""
"""Standard error response
(deprecated, use ErrorResponse instead)
"""
code
:
int
=
400
message
:
str
errors
:
list
[
dict
]
|
None
=
None
...
...
frontend/src/api/auth.ts
浏览文件 @
a5e3136b
...
...
@@ -15,7 +15,7 @@ export interface ApiResponse<T> {
// 登录请求
export
interface
LoginRequest
{
email
:
string
identifier
:
string
password
:
string
}
...
...
@@ -76,10 +76,10 @@ export const AuthAPI = {
/**
* 用户登录
*/
async
login
(
email
:
string
,
password
:
string
):
Promise
<
LoginResponse
>
{
async
login
(
identifier
:
string
,
password
:
string
):
Promise
<
LoginResponse
>
{
const
response
=
await
request
<
ApiResponse
<
LoginResponse
>>
(
'/auth/login'
,
{
method
:
'POST'
,
body
:
JSON
.
stringify
({
email
,
password
}),
body
:
JSON
.
stringify
({
identifier
,
password
}),
})
if
(
response
.
code
!==
200
)
{
...
...
@@ -91,9 +91,11 @@ export const AuthAPI = {
/**
* 用户注册
* 注意:注册成功后返回用户信息,不包含 access_token
* 注册完成后需要用户手动登录
*/
async
register
(
username
:
string
,
email
:
string
,
password
:
string
):
Promise
<
Login
Response
>
{
const
response
=
await
request
<
ApiResponse
<
Login
Response
>>
(
'/auth/register'
,
{
async
register
(
username
:
string
,
email
:
string
,
password
:
string
):
Promise
<
User
Response
>
{
const
response
=
await
request
<
ApiResponse
<
User
Response
>>
(
'/auth/register'
,
{
method
:
'POST'
,
body
:
JSON
.
stringify
({
username
,
email
,
password
}),
})
...
...
frontend/src/components/layout/Header.vue
浏览文件 @
a5e3136b
...
...
@@ -79,7 +79,7 @@ const isActive = (path: string) => {
return
route
.
path
.
startsWith
(
path
)
}
const
handleCommand
=
(
command
:
string
)
=>
{
const
handleCommand
=
async
(
command
:
string
)
=>
{
switch
(
command
)
{
case
'profile'
:
ElMessageBox
.
alert
(
'个人中心功能开发中...'
,
'提示'
)
...
...
@@ -92,8 +92,8 @@ const handleCommand = (command: string) => {
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
}).
then
(()
=>
{
userStore
.
logout
()
}).
then
(
async
()
=>
{
await
userStore
.
logout
()
router
.
push
(
'/login'
)
}).
catch
(()
=>
{})
break
...
...
frontend/src/store/user.ts
浏览文件 @
a5e3136b
...
...
@@ -32,15 +32,15 @@ export const useUserStore = defineStore('user', () => {
/**
* 用户登录
* @param
email 邮箱
* @param
identifier 邮箱或用户名
* @param password 密码
*/
async
function
login
(
email
:
string
,
password
:
string
):
Promise
<
boolean
>
{
async
function
login
(
identifier
:
string
,
password
:
string
):
Promise
<
boolean
>
{
loading
.
value
=
true
error
.
value
=
null
try
{
const
response
=
await
AuthAPI
.
login
(
email
,
password
)
const
response
=
await
AuthAPI
.
login
(
identifier
,
password
)
token
.
value
=
response
.
access_token
currentUser
.
value
=
convertToUser
(
response
.
user
)
...
...
@@ -64,6 +64,7 @@ export const useUserStore = defineStore('user', () => {
* @param username 用户名
* @param email 邮箱
* @param password 密码
* @returns 返回注册后的用户信息,不包含 access_token
*/
async
function
register
(
username
:
string
,
password
:
string
,
email
:
string
):
Promise
<
boolean
>
{
loading
.
value
=
true
...
...
@@ -72,14 +73,8 @@ export const useUserStore = defineStore('user', () => {
try
{
const
response
=
await
AuthAPI
.
register
(
username
,
email
,
password
)
token
.
value
=
response
.
access_token
currentUser
.
value
=
convertToUser
(
response
.
user
)
isLoggedIn
.
value
=
true
// 存储到 localStorage
localStorage
.
setItem
(
'plabel_token'
,
response
.
access_token
)
localStorage
.
setItem
(
'plabel_user'
,
JSON
.
stringify
(
currentUser
.
value
))
// 注册成功,返回 true,由调用方处理页面跳转
// 注意:注册成功后不保存 token,用户需要重新登录
return
true
}
catch
(
err
:
any
)
{
error
.
value
=
err
.
message
||
'注册失败'
...
...
frontend/src/views/auth/Login.vue
浏览文件 @
a5e3136b
...
...
@@ -19,10 +19,10 @@
class=
"login-form"
@
submit
.
prevent=
"handleLogin"
>
<el-form-item
prop=
"
email
"
>
<el-form-item
prop=
"
identifier
"
>
<el-input
v-model=
"loginForm.
email
"
placeholder=
"请输入邮箱"
v-model=
"loginForm.
identifier
"
placeholder=
"请输入邮箱
或用户名
"
size=
"large"
:prefix-icon=
"Message"
/>
...
...
@@ -87,15 +87,14 @@ const loginFormRef = ref<FormInstance>()
const
loading
=
ref
(
false
)
const
loginForm
=
reactive
({
email
:
''
,
identifier
:
''
,
password
:
''
,
remember
:
false
})
const
rules
:
FormRules
=
{
email
:
[
{
required
:
true
,
message
:
'请输入邮箱'
,
trigger
:
'blur'
},
{
type
:
'email'
,
message
:
'请输入正确的邮箱格式'
,
trigger
:
'blur'
}
identifier
:
[
{
required
:
true
,
message
:
'请输入邮箱或用户名'
,
trigger
:
'blur'
}
],
password
:
[
{
required
:
true
,
message
:
'请输入密码'
,
trigger
:
'blur'
},
...
...
@@ -110,12 +109,12 @@ const handleLogin = async () => {
if
(
valid
)
{
loading
.
value
=
true
try
{
const
success
=
await
userStore
.
login
(
loginForm
.
email
,
loginForm
.
password
)
const
success
=
await
userStore
.
login
(
loginForm
.
identifier
,
loginForm
.
password
)
if
(
success
)
{
ElMessage
.
success
(
'登录成功,欢迎回来!'
)
router
.
push
(
'/dashboard'
)
}
else
{
ElMessage
.
error
(
userStore
.
error
||
'登录失败,请检查邮箱和密码'
)
ElMessage
.
error
(
userStore
.
error
||
'登录失败,请检查邮箱
/用户名
和密码'
)
}
}
catch
{
ElMessage
.
error
(
'登录失败,请重试'
)
...
...
frontend/src/views/auth/Register.vue
浏览文件 @
a5e3136b
...
...
@@ -151,8 +151,8 @@ const handleRegister = async () => {
registerForm
.
email
)
if
(
success
)
{
ElMessage
.
success
(
'注册成功!'
)
router
.
push
(
'/
dashboard
'
)
ElMessage
.
success
(
'注册成功!
请使用您的账号密码登录。
'
)
router
.
push
(
'/
login
'
)
}
else
{
ElMessage
.
error
(
userStore
.
error
||
'注册失败,请重试'
)
}
...
...
logs/Vue_8008.log
浏览文件 @
a5e3136b
No preview for this file type
logs/vue_8008.pid
浏览文件 @
a5e3136b
162300
339721
md/后端需求清单.md
浏览文件 @
a5e3136b
...
...
@@ -1100,6 +1100,8 @@ CREATE INDEX idx_annotations_user ON annotations(user_id);
### 7.2 认证接口
#### 7.2.1 用户登录
```
python
# POST /api/v1/auth/login
# 请求
...
...
@@ -1126,6 +1128,85 @@ CREATE INDEX idx_annotations_user ON annotations(user_id);
}
```
#### 7.2.3 用户登出
```
python
# POST /api/v1/auth/logout
# 请求(无需认证)
# 响应
{
"code"
:
200
,
"message"
:
"Successfully logged out"
,
"data"
:
{}
}
```
**说明**
:由于使用 JWT 无状态认证,logout 由客户端处理(清除本地 token),后端 logout 接口不需要认证。
**重要说明**
:用户注册成功后
**不会自动登录**
,而是跳转到登录页面让用户手动输入账号密码进行登录。这是安全最佳实践。
```
python
# POST /api/v1/auth/register
# 请求
{
"username"
:
"newuser"
,
"email"
:
"newuser@example.com"
,
"password"
:
"password123"
}
# 响应
{
"code"
:
200
,
"data"
:
{
"id"
:
"uuid"
,
"username"
:
"newuser"
,
"email"
:
"newuser@example.com"
,
"created_at"
:
"2026-05-29T10:00:00Z"
},
"message"
:
"注册成功,请使用账号密码登录"
}
# 注册失败响应(用户名或邮箱已存在)
{
"code"
:
400
,
"message"
:
"用户名或邮箱已被注册"
,
"errors"
:
[
{
"field"
:
"email"
,
"message"
:
"该邮箱已被注册"
}
]
}
```
#### 7.2.3 注册业务流程
```
用户注册页面 (/register)
│
│ 填写表单:用户名、邮箱、密码、确认密码
│
▼
点击注册按钮
│
│ 发送 POST /api/v1/auth/register
▼
┌──────────────────┐
│ 后端验证 │
│ - 邮箱格式校验 │
│ - 密码强度校验 │
│ - 唯一性校验 │
└────────┬─────────┘
│
▼
┌──────────────┐
│ 注册成功 │──────────────────────▶ 跳转登录页 /login
└──────────────┘ │
│ 用户输入账号密码
▼
┌──────────────┐
│ 调用登录接口 │
│ 获取 Token │
└──────────────┘
```
### 7.3 核心接口列表
| 模块 | 接口数 | 主要功能 |
...
...
@@ -1238,7 +1319,7 @@ async def get_presigned_url(task_id: str, file_name: str, content_type: str):
| 功能 | 优先级 | 说明 |
|------|--------|------|
| 用户注册 | P0 | 邮箱、用户名、密码 |
| 用户注册 | P0 | 邮箱、用户名、密码
;
**注册成功后跳转登录页,不自动登录**
|
| 用户登录 | P0 | JWT Token 认证 |
| 密码修改 | P1 | 旧密码验证 |
| 角色权限 | P0 | admin/user/annotator/reviewer |
...
...
@@ -1633,8 +1714,10 @@ CORS_ORIGINS = [
---
*文档版本: v2.
0
*
*文档版本: v2.
2
*
*创建日期: 2026年5月28日*
*更新记录:*
-
v2.2 (2026-05-29): 修复登出逻辑,logout 接口不再需要认证,解决需要点两次才能退出的问题
-
v2.1 (2026-05-29): 更新注册流程逻辑,注册成功后返回用户信息而非 access_token,用户需手动登录
-
v2.0 (2026-05-28): 全面更新,详细规划后端项目结构、增加开发里程碑
-
v1.0 (2026-05-28): 初始版本
scripts/start-services.sh
浏览文件 @
a5e3136b
#!/bin/bash
# PLabel 服务启动脚本 一键重启所有服务
# PLabel 服务管理脚本
# 用法: bash start-services.sh [start|restart|stop|status]
# Phase 0: 项目初始化、环境搭建
set
-e
SCRIPT_DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
echo
"=========================================="
echo
" PLabel 服务启动脚本"
echo
"=========================================="
echo
""
cd
"
$SCRIPT_DIR
"
# 颜色定义
GREEN
=
'\033[0;32m'
YELLOW
=
'\033[1;33m'
RED
=
'\033[0;31m'
NC
=
'\033[0m'
# No Color
BLUE
=
'\033[0;34m'
NC
=
'\033[0m'
# 服务列表
SERVICES
=(
"plabel-postgres"
"plabel-minio"
)
# 显示帮助
show_help
()
{
echo
-e
"
${
BLUE
}
PLabel 服务管理脚本
${
NC
}
"
echo
""
echo
"用法:
$0
[命令]"
echo
""
echo
-e
"
${
GREEN
}
命令:
${
NC
}
"
echo
" start - 启动所有服务"
echo
" stop - 停止所有服务"
echo
" restart - 重启所有服务"
echo
" status - 查看服务状态"
echo
""
echo
-e
"
${
GREEN
}
示例:
${
NC
}
"
echo
"
$0
start # 启动服务"
echo
"
$0
stop # 停止服务"
echo
"
$0
restart # 重启服务"
echo
"
$0
status # 查看状态"
echo
""
}
# 检查Docker是否运行
check_docker
()
{
...
...
@@ -23,14 +42,28 @@ check_docker() {
echo
-e
"
${
RED
}
错误: Docker未运行,请先启动Docker
${
NC
}
"
exit
1
fi
echo
-e
"
${
GREEN
}
✓ Docker已运行
${
NC
}
"
}
# 检查服务是否存在
service_exists
()
{
docker ps
-a
--format
'{{.Names}}'
|
grep
-q
"^
$1
$"
}
# 检查服务是否运行
service_running
()
{
docker ps
--format
'{{.Names}}'
|
grep
-q
"^
$1
$"
}
# 启动PostgreSQL
start_postgres
()
{
echo
-e
"
\n
${
YELLOW
}
启动 PostgreSQL...
${
NC
}
"
if
docker ps
-a
--format
'{{.Names}}'
|
grep
-q
"^plabel-postgres$"
;
then
docker start plabel-postgres 2>/dev/null
||
true
if
service_exists
"plabel-postgres"
;
then
if
service_running
"plabel-postgres"
;
then
echo
-e
"
${
GREEN
}
✓ PostgreSQL 已在运行
${
NC
}
"
else
docker start plabel-postgres
echo
-e
"
${
GREEN
}
✓ PostgreSQL 已启动 (端口: 5433)
${
NC
}
"
fi
else
docker run
-d
\
--name
plabel-postgres
\
...
...
@@ -41,15 +74,20 @@ start_postgres() {
-p
0.0.0.0:5433:5432
\
--restart
unless-stopped
\
docker.m.daocloud.io/library/postgres:15-alpine
echo
-e
"
${
GREEN
}
✓ PostgreSQL 已创建并启动 (端口: 5433)
${
NC
}
"
fi
echo
-e
"
${
GREEN
}
✓ PostgreSQL 已启动 (端口: 5433)
${
NC
}
"
}
# 启动MinIO
start_minio
()
{
echo
-e
"
\n
${
YELLOW
}
启动 MinIO...
${
NC
}
"
if
docker ps
-a
--format
'{{.Names}}'
|
grep
-q
"^plabel-minio$"
;
then
docker start plabel-minio 2>/dev/null
||
true
if
service_exists
"plabel-minio"
;
then
if
service_running
"plabel-minio"
;
then
echo
-e
"
${
GREEN
}
✓ MinIO 已在运行
${
NC
}
"
else
docker start plabel-minio
echo
-e
"
${
GREEN
}
✓ MinIO 已启动 (API: 9009, Console: 9010)
${
NC
}
"
fi
else
docker run
-d
\
--name
plabel-minio
\
...
...
@@ -60,46 +98,39 @@ start_minio() {
-p
9010:9010
\
--restart
unless-stopped
\
docker.m.daocloud.io/minio/minio:latest server /data
--console-address
":9010"
echo
-e
"
${
GREEN
}
✓ MinIO 已创建并启动 (API: 9009, Console: 9010)
${
NC
}
"
fi
echo
-e
"
${
GREEN
}
✓ MinIO 已启动 (API: 9009, Console: 9010)
${
NC
}
"
}
#
创建
MinIO存储桶
#
配置
MinIO存储桶
setup_minio_bucket
()
{
echo
-e
"
\n
${
YELLOW
}
配置 MinIO 存储桶...
${
NC
}
"
sleep
3
MINIO_IP
=
$(
docker inspect plabel-minio
--format
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
)
docker
exec
plabel-minio mc
alias set local
http://
${
MINIO_IP
}
:9000 minio minio123 2>/dev/null
||
true
docker
exec
plabel-minio mc mb
local
/plabel-bucket
--ignore-existing
2>/dev/null
||
true
echo
-e
"
${
GREEN
}
✓ MinIO 存储桶已
创建
${
NC
}
"
echo
-e
"
${
GREEN
}
✓ MinIO 存储桶已
配置
${
NC
}
"
}
# 验证服务
verify_services
()
{
echo
-e
"
\n
${
YELLOW
}
验证服务状态...
${
NC
}
"
sleep
5
# PostgreSQL
if
docker
exec
plabel-postgres pg_isready
-U
plabel
>
/dev/null 2>&1
;
then
echo
-e
"
${
GREEN
}
✓ PostgreSQL: localhost:5433
${
NC
}
"
else
echo
-e
"
${
RED
}
✗ PostgreSQL 连接失败
${
NC
}
"
fi
sleep
3
# MinIO
MINIO_IP
=
$(
docker inspect plabel-minio
--format
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
)
if
docker
exec
plabel-minio mc
ls local
/
>
/dev/null 2>&1
;
then
echo
-e
"
${
GREEN
}
✓ MinIO: localhost:9009 (Console: localhost:9010)
${
NC
}
"
for
svc
in
"
${
SERVICES
[@]
}
"
;
do
if
service_running
"
$svc
"
;
then
echo
-e
"
${
GREEN
}
✓
$svc
: 运行中
${
NC
}
"
else
echo
-e
"
${
RED
}
✗ MinIO 连接失败
${
NC
}
"
echo
-e
"
${
RED
}
✗
$svc
: 已停止
${
NC
}
"
fi
done
}
# 显示
访问
信息
# 显示
服务
信息
show_info
()
{
echo
-e
"
\n
==========================================
"
echo
-e
"
服务访问信息
"
echo
-e
"
==========================================
"
echo
-e
"
\n
${
BLUE
}
==========================================
${
NC
}
"
echo
-e
"
${
BLUE
}
服务访问信息
${
NC
}
"
echo
-e
"
${
BLUE
}
==========================================
${
NC
}
"
echo
""
echo
-e
"
${
GREEN
}
PostgreSQL:
${
NC
}
"
echo
-e
" 地址: localhost:5433"
...
...
@@ -119,14 +150,50 @@ show_info() {
echo
-e
" 文档: http://localhost:8899/docs"
echo
""
echo
-e
"
${
GREEN
}
启动后端命令:
${
NC
}
"
echo
-e
" cd
$SCRIPT_DIR
/backend"
echo
-e
" /datacore/home/admin2/miniconda3/envs/plabel/bin/uvicorn app.main:app --host 0.0.0.0 --port 8899 --reload"
echo
" cd
$SCRIPT_DIR
/backend"
echo
" /datacore/home/admin2/miniconda3/envs/plabel/bin/uvicorn app.main:app --host 0.0.0.0 --port 8899 --reload"
echo
""
}
# 主函数
main
()
{
# 显示服务状态
show_status
()
{
echo
-e
"
\n
${
BLUE
}
==========================================
${
NC
}
"
echo
-e
"
${
BLUE
}
PLabel 服务状态
${
NC
}
"
echo
-e
"
${
BLUE
}
==========================================
${
NC
}
"
echo
""
for
svc
in
"
${
SERVICES
[@]
}
"
;
do
if
service_running
"
$svc
"
;
then
ports
=
$(
docker port
"
$svc
"
2>/dev/null |
tr
'\n'
' '
||
echo
"N/A"
)
echo
-e
"
${
GREEN
}
●
$svc
${
NC
}
- 运行中"
echo
-e
" 端口:
$ports
"
else
echo
-e
"
${
RED
}
○
$svc
${
NC
}
- 已停止"
fi
done
echo
""
}
# 停止服务
stop_services
()
{
echo
-e
"
\n
${
YELLOW
}
停止所有服务...
${
NC
}
"
for
svc
in
"
${
SERVICES
[@]
}
"
;
do
if
service_running
"
$svc
"
;
then
docker stop
"
$svc
"
echo
-e
"
${
GREEN
}
✓
$svc
已停止
${
NC
}
"
else
echo
-e
"
${
YELLOW
}
○
$svc
未运行
${
NC
}
"
fi
done
}
# 启动所有服务
start_services
()
{
check_docker
echo
-e
"
${
BLUE
}
==========================================
${
NC
}
"
echo
-e
"
${
BLUE
}
启动 PLabel 服务
${
NC
}
"
echo
-e
"
${
BLUE
}
==========================================
${
NC
}
"
start_postgres
start_minio
setup_minio_bucket
...
...
@@ -134,4 +201,44 @@ main() {
show_info
}
# 重启所有服务
restart_services
()
{
echo
-e
"
${
BLUE
}
==========================================
${
NC
}
"
echo
-e
"
${
BLUE
}
重启 PLabel 服务
${
NC
}
"
echo
-e
"
${
BLUE
}
==========================================
${
NC
}
"
stop_services
sleep
2
start_services
}
# 主函数
main
()
{
case
"
${
1
:-}
"
in
start
)
start_services
;;
stop
)
check_docker
stop_services
;;
restart
)
check_docker
restart_services
;;
status
)
check_docker
show_status
;;
help
|
--help
|
-h
)
show_help
;;
*
)
echo
-e
"
${
RED
}
未知命令:
$1
${
NC
}
"
show_help
exit
1
;;
esac
}
main
"
$@
"
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论