本文整理匯總了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