本文整理汇总了Python中rest_framework_jwt.settings.api_settings.JWT_RESPONSE_PAYLOAD_HANDLER属性的典型用法代码示例。如果您正苦于以下问题:Python api_settings.JWT_RESPONSE_PAYLOAD_HANDLER属性的具体用法?Python api_settings.JWT_RESPONSE_PAYLOAD_HANDLER怎么用?Python api_settings.JWT_RESPONSE_PAYLOAD_HANDLER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类rest_framework_jwt.settings.api_settings
的用法示例。
在下文中一共展示了api_settings.JWT_RESPONSE_PAYLOAD_HANDLER属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validated
# 需要导入模块: from rest_framework_jwt.settings import api_settings [as 别名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_RESPONSE_PAYLOAD_HANDLER [as 别名]
def validated(self, serialized_data, *args, **kwargs):
from rest_framework_jwt.settings import api_settings
from datetime import datetime
from .models import AuthTransaction
from drfaddons.utils import get_client_ip
from rest_framework.response import Response
user = serialized_data.object.get('user') or self.request.user
token = serialized_data.object.get('token')
response_data = api_settings.JWT_RESPONSE_PAYLOAD_HANDLER(token, user,
self.request)
response = Response(response_data)
if api_settings.JWT_AUTH_COOKIE:
expiration = (datetime.utcnow() +
api_settings.JWT_EXPIRATION_DELTA)
response.set_cookie(api_settings.JWT_AUTH_COOKIE,
token,
expires=expiration,
httponly=True)
user.last_login = datetime.now()
user.save()
AuthTransaction(created_by=user, token=token,
ip_address=get_client_ip(self.request),
session=user.get_session_auth_hash()).save()
return response