<gh_stars>0
# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2021, Shuup Commerce Inc. All rights reserved.
#
# This source code is licensed under the Shuup Commerce Inc -
# SELF HOSTED SOFTWARE LICENSE AGREEMENT executed by Shuup Commerce Inc, DBA as SHUUP®
# and the Licensee.
# See https://stackoverflow.com/questions/14567586/
from rest_framework.authtoken import views
from rest_framework.authtoken.models import Token
from rest_framework.response import Response


class ObtainExpiringAuthToken(views.ObtainAuthToken):
    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data, context={"request": request})
        serializer.is_valid(raise_exception=True)
        token, created = Token.objects.get_or_create(user=serializer.validated_data["user"])
        if not created:
            token.delete()
            token = Token.objects.create(user=serializer.validated_data["user"])

        return Response({"token": token.key})


refresh_auth_token = ObtainExpiringAuthToken.as_view()

# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2021, Shuup Commerce Inc. All rights reserved.
#
# This source code is licensed under the Shuup Commerce Inc -
# SELF HOSTED SOFTWARE LICENSE AGREEMENT executed by Shuup Commerce Inc, DBA as SHUUP®
# and the Licensee.
# See https://stackoverflow.com/questions/14567586/
from rest_framework.authtoken import views
from rest_framework.authtoken.models import Token
from rest_framework.response import Response


class ObtainExpiringAuthToken(views.ObtainAuthToken):
    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data, context={"request": request})
        serializer.is_valid(raise_exception=True)
        token, created = Token.objects.get_or_create(user=serializer.validated_data["user"])
        if not created:
            token.delete()
            token = Token.objects.create(user=serializer.validated_data["user"])

        return Response({"token": token.key})


refresh_auth_token = ObtainExpiringAuthToken.as_view()
# -*- coding: utf-8 -*- # This file is part of Shuup. # # Copyright (c) 2012-2021, Shuup Commerce Inc. All rights reserved. # # This source code is licensed under the Shuup Commerce Inc - # SELF HOSTED SOFTWARE LICENSE AGREEMENT executed by Shuup Commerce Inc, DBA as SHUUP® # and the Licensee. # See https://stackoverflow.com/questions/14567586/