加上登录和角色权限,并用 Vue 控制台区分用户与管理员。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-10 22:43:31 +08:00
parent 78601aae5e
commit 8b55b9cf55
36 changed files with 2947 additions and 1007 deletions
+58 -1
View File
@@ -8,10 +8,11 @@ from typing import Annotated
from pydantic import BaseModel, ConfigDict, Field, PlainSerializer
from app.models import NodeStatus, TaskStatus, WithdrawalStatus, YieldStatus
from app.models import NodeStatus, TaskStatus, UserRole, WithdrawalStatus, YieldStatus
SN = Annotated[str, Field(min_length=4, max_length=64, pattern=r"^[A-Za-z0-9_-]+$")]
WALLET = Annotated[str, Field(min_length=4, max_length=128, pattern=r"^[A-Za-z0-9:_-]+$")]
USERNAME = Annotated[str, Field(min_length=3, max_length=32, pattern=r"^[A-Za-z0-9_]+$")]
MoneyText = Annotated[Decimal, PlainSerializer(lambda value: format(value, "f"), return_type=str)]
@@ -26,9 +27,41 @@ class UserCreate(APIModel):
class UserOut(APIModel):
id: int
wallet_address: str
username: str | None = None
role: UserRole = UserRole.USER
created_at: datetime
class RegisterIn(APIModel):
wallet_address: WALLET
username: USERNAME | None = None
password: str | None = Field(default=None, max_length=72)
class LoginIn(APIModel):
wallet_address: str | None = Field(default=None, max_length=128)
username: str | None = Field(default=None, max_length=32)
password: str | None = Field(default=None, max_length=72)
class TokenOut(APIModel):
access_token: str
token_type: str = "bearer"
role: UserRole
wallet_address: str
username: str | None = None
class AdminUserOut(APIModel):
id: int
wallet_address: str
username: str | None
role: UserRole
created_at: datetime
node_count: int
available_points: MoneyText
class NodeCreate(APIModel):
wallet_address: WALLET
sn: SN
@@ -51,6 +84,8 @@ class NodeOut(APIModel):
class NodeView(NodeOut):
wallet_address: str
online_rate: MoneyText = Decimal("0")
today_points: MoneyText = Decimal("0")
class HeartbeatIn(APIModel):
@@ -134,6 +169,17 @@ class WithdrawalCreate(APIModel):
asset_symbol: str = Field(default="POINT", min_length=1, max_length=32)
class MeWithdrawalCreate(APIModel):
amount: Decimal = Field(gt=0, max_digits=24, decimal_places=8)
asset_symbol: str = Field(default="POINT", min_length=1, max_length=32)
class MeNodeCreate(APIModel):
sn: SN
purchase_amount: Decimal = Field(gt=0, max_digits=24, decimal_places=8)
callback_url: str | None = None
class WithdrawalConfirm(APIModel):
tx_hash: str = Field(min_length=6, max_length=128, pattern=r"^[A-Za-z0-9]+$")
@@ -172,3 +218,14 @@ class SummaryOut(APIModel):
authorized_amount: MoneyText
settled_points: MoneyText
pending_withdrawals: MoneyText
class DashboardOut(APIModel):
wallet_address: str
username: str | None
role: UserRole
available_points: MoneyText
settled_points: MoneyText
today_points: MoneyText
nodes: list[NodeView]
withdrawals: list[WithdrawalOut]