perf: Optimize the writing method of getting HTTP_AUTHORIZATION (#114)

This commit is contained in:
feng626 2024-04-16 22:55:34 +08:00 committed by GitHub
parent 5e499e6afa
commit 11f0a82e68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 7 deletions

View File

@ -196,7 +196,7 @@ class ApplicationSerializer(serializers.Serializer):
access_token = serializers.CharField(required=True, error_messages=ErrMessage.char("access_token"))
def auth(self, request, with_valid=True):
token = request.META.get('HTTP_AUTHORIZATION', None)
token = request.META.get('HTTP_AUTHORIZATION')
token_details = None
try:
# 校验token

View File

@ -47,8 +47,7 @@ class TokenDetails:
class TokenAuth(TokenAuthentication):
# 重新 authenticate 方法,自定义认证规则
def authenticate(self, request):
auth = request.META.get('HTTP_AUTHORIZATION', None
)
auth = request.META.get('HTTP_AUTHORIZATION')
# 未认证
if auth is None:
raise AppAuthenticationFailed(1003, '未登录,请先登录')

View File

@ -88,8 +88,7 @@ class ResetCurrentUserPasswordView(APIView):
data.update(request.data)
serializer_obj = RePasswordSerializer(data=data)
if serializer_obj.reset_password():
token_cache.delete(request.META.get('HTTP_AUTHORIZATION', None
))
token_cache.delete(request.META.get('HTTP_AUTHORIZATION'))
return result.success(True)
return result.error("修改密码失败")
@ -119,8 +118,7 @@ class Logout(APIView):
responses=SendEmailSerializer().get_response_body_api(),
tags=['用户'])
def post(self, request: Request):
token_cache.delete(request.META.get('HTTP_AUTHORIZATION', None
))
token_cache.delete(request.META.get('HTTP_AUTHORIZATION'))
return result.success(True)