Skip to content

Commit

Permalink
feat: 用户鉴权
Browse files Browse the repository at this point in the history
基于角色的,将权限内置于代码内。
等待测试。
  • Loading branch information
XYCode-Kerman committed Apr 15, 2024
1 parent 7e94ec6 commit 8e6d02b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions ccf_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ccf_parser.base import CCF, CCFHeader, Contest
from ccf_parser.configs import ContestIndex, ContestIndexList
from ccf_parser.oj import OJConfig
from ccf_parser.problems import CheckPoint, JudgeConfig, Problem
from ccf_parser.results import CheckPointResult, JudgingResult
4 changes: 3 additions & 1 deletion ccf_parser/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pathlib
from typing import List, Literal
from typing import List, Literal, Optional

from pydantic import BaseModel

from ccf_parser.oj import OJConfig
from ccf_parser.problems import Problem


Expand All @@ -12,6 +13,7 @@ class CCFHeader(BaseModel):
description: str
contest_type: Literal['OI', 'IOI']
enable_oj: bool
oj_config: Optional[OJConfig] = None


class Contest(BaseModel):
Expand Down
8 changes: 8 additions & 0 deletions ccf_parser/oj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from datetime import datetime

from pydantic import BaseModel


class OJConfig(BaseModel):
start_time: datetime
end_time: datetime
10 changes: 10 additions & 0 deletions online_judge/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def get_token(user: User) -> str:
)


def require_role(roles: List[str] = ['default']) -> Callable[[User], User]:
def wrapper(user: User = Depends(get_user)) -> User:
if user.role not in roles:
raise HTTPException(status_code=403, detail="不符合权限要求")

return user

return wrapper


@router.post('/login', name='登录', responses={
200: {
"description": "登录成功",
Expand Down

0 comments on commit 8e6d02b

Please sign in to comment.