Files
DjangoAdmin_FastAPI_EleVue/core/security.py
T
ClaudeandClaude db4ee85db5 feat(phase1): core/ 基础设施迁移,旧路径改垫片
- core/: database/redis_client/jwt/password/response/exceptions/security/logger/deps/middleware/app
- create_app 迁移到 core/app.py,中间件注册顺序与异常处理器原样保留
- extensions/ utils/ apps/ 旧文件全部改为 re-export 垫片,import 路径保持兼容
- 新增 core 单元测试(jwt/password/response/request 共 12 个)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-07 10:02:01 +08:00

25 lines
984 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# +======================================================================
# | DjangoAdmin 企业数字化开发平台 [ 赋能开发者,助力企业发展 ]
# +----------------------------------------------------------------------
# | Copyright (c) 2021-2026 一米阳光团队 版权所有
# | 开源协议: Apache-2.0
# +======================================================================
# 由 utils/security.py 迁移而来。
"""安全辅助:从请求上下文获取当前用户信息,并组合 jwt + password 提供安全便捷函数。"""
def get_user_id(request) -> int:
"""获取当前请求的用户ID(由 login_required 中间件注入 request.state)"""
return getattr(request.state, 'user_id', 0)
def get_username(request) -> str:
"""获取当前请求的用户名"""
return getattr(request.state, 'username', '')
def get_realname(request) -> str:
"""获取当前请求的姓名"""
return getattr(request.state, 'realname', '')