You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
899 B
28 lines
899 B
from rest_framework.response import Response
|
|
from rest_framework.decorators import api_view, permission_classes
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
|
from rest_framework_simplejwt.views import TokenObtainPairView
|
|
|
|
from base.serializer import ProfileSerializer
|
|
|
|
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
|
|
@classmethod
|
|
def get_token(cls, user):
|
|
token = super().get_token(user)
|
|
|
|
token['username'] = user.username
|
|
|
|
return token
|
|
|
|
class MyTokenObtainPairView(TokenObtainPairView):
|
|
serializer_class = MyTokenObtainPairSerializer
|
|
|
|
@api_view(['GET'])
|
|
@permission_classes([IsAuthenticated])
|
|
def get_profile(request):
|
|
user = request.user
|
|
profile = user.profile
|
|
serializer = ProfileSerializer(profile, many=False)
|
|
return Response(serializer.data)
|
|
|