haha
This commit is contained in:
@@ -41,3 +41,29 @@ def login(request):
|
||||
)
|
||||
|
||||
return Response({"token": token})
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
def get_info(request):
|
||||
"""
|
||||
获取当前登录账号的详细信息:
|
||||
- 从 Authorization 头解析 token
|
||||
- 查 AuthToken 表反查用户名
|
||||
- 返回用户名、登录时间等
|
||||
"""
|
||||
auth_header = request.headers.get("Authorization", "")
|
||||
token = auth_header.replace("Bearer ", "").strip() if auth_header else ""
|
||||
|
||||
if not token:
|
||||
return Response({"detail": "未提供认证令牌"}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
try:
|
||||
record = AuthToken.objects.get(token=token)
|
||||
except AuthToken.DoesNotExist:
|
||||
return Response({"detail": "令牌无效或已过期"}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
return Response({
|
||||
"username": record.username,
|
||||
"token": record.token,
|
||||
"created_at": record.created_at,
|
||||
})
|
||||
|
||||
@@ -12,6 +12,7 @@ urlpatterns = [
|
||||
|
||||
# ─── 认证 ───
|
||||
path("api/auth/login", auth.login),
|
||||
path("api/auth/get_info", auth.get_info),
|
||||
|
||||
# ─── Worker ───
|
||||
path("api/workers", workers.worker_list),
|
||||
|
||||
Reference in New Issue
Block a user