Download apps/organization/api/auth_api.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/organization/api/auth_api.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/organization/api/auth_api.py
-
curl -L -o auth_api.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/organization/api/auth_api.py
1.26 kB
| """ | |
| 认证 API 模块 | |
| 提供用户登录、登出和当前用户信息接口 | |
| """ | |
| from typing import cast | |
| from django.http import HttpRequest | |
| from ninja import Router | |
| from apps.core.infrastructure.throttling import rate_limit_from_settings | |
| from apps.core.security.auth import JWTOrSessionAuth | |
| from apps.organization.schemas import LawyerOut, LoginIn, LoginOut | |
| from apps.organization.services import AuthService | |
| router = Router() | |
| def _get_auth_service() -> AuthService: | |
| """工厂函数:获取认证服务实例""" | |
| return AuthService() | |
| _auth_service = _get_auth_service() | |
| def login_view(request: HttpRequest, payload: LoginIn) -> LoginOut: | |
| user = _auth_service.login(request, payload.username, payload.password) | |
| user_out = cast(LawyerOut, LawyerOut.from_orm(user)) | |
| return LoginOut(success=True, user=user_out) | |
| def logout_view(request: HttpRequest) -> dict[str, bool]: | |
| _auth_service.logout(request) | |
| return {"success": True} | |
| def me_view(request: HttpRequest) -> LawyerOut: | |
| return cast(LawyerOut, LawyerOut.from_orm(request.user)) | |