create initial models and mobile test for mojtaba eshaghi
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from apps.authentication.api.v1.serializers.jwt import CustomizedTokenObtainPairSerializer
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.decorators import action
|
||||
@@ -10,10 +11,12 @@ class CustomizedTokenObtainPairView(TokenObtainPairView):
|
||||
serializer_class = CustomizedTokenObtainPairSerializer
|
||||
|
||||
|
||||
# Example Code
|
||||
class Authentication(ModelViewSet):
|
||||
queryset = User
|
||||
serializer_class = ''
|
||||
permission_classes = ''
|
||||
authentication_classes = [JWTAuthentication]
|
||||
|
||||
@action(
|
||||
methods=['post', ],
|
||||
|
||||
@@ -2,6 +2,7 @@ from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||
from apps.captcha_app import exceptions as captcha_exception
|
||||
from rest_framework_simplejwt.settings import api_settings
|
||||
from django.contrib.auth.models import update_last_login
|
||||
from apps.authentication.models import User
|
||||
from rest_framework import exceptions
|
||||
from django.core.cache import cache
|
||||
from typing import Any
|
||||
@@ -51,9 +52,12 @@ class CustomizedTokenObtainPairSerializer(TokenObtainPairSerializer): # noqa
|
||||
|
||||
token = super().get_token(user)
|
||||
|
||||
# get customized user
|
||||
auth_user_model = User.objects.get(username=user.username)
|
||||
|
||||
# Add custom claims
|
||||
token['name'] = user.username
|
||||
token['mobile'] = user.mobile
|
||||
token['national_code'] = user.national_code
|
||||
token['mobile'] = auth_user_model.mobile
|
||||
token['national_code'] = auth_user_model.national_code
|
||||
|
||||
return token
|
||||
|
||||
Reference in New Issue
Block a user