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
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 07:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0004_user_otp_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='address',
|
||||
field=models.TextField(max_length=1000, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='birthdate',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='nationality',
|
||||
field=models.CharField(max_length=20, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='ownership',
|
||||
field=models.IntegerField(default=1, help_text='number 1 is natural & number 2 is legal'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='phone',
|
||||
field=models.CharField(max_length=18, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='photo',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
),
|
||||
]
|
||||
17
apps/authentication/migrations/0006_remove_user_ownership.py
Normal file
17
apps/authentication/migrations/0006_remove_user_ownership.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 08:20
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0005_user_address_user_birthdate_user_nationality_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='user',
|
||||
name='ownership',
|
||||
),
|
||||
]
|
||||
18
apps/authentication/migrations/0007_user_ownership.py
Normal file
18
apps/authentication/migrations/0007_user_ownership.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.20 on 2025-05-05 08:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0006_remove_user_ownership'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='ownership',
|
||||
field=models.CharField(choices=[('N', 'Natural'), ('L', 'Legal')], default='N', help_text='N is natural & L is legal', max_length=1),
|
||||
),
|
||||
]
|
||||
@@ -7,8 +7,22 @@ from apps.core.models import BaseModel
|
||||
|
||||
class User(AbstractUser, BaseModel):
|
||||
mobile = models.CharField(max_length=18)
|
||||
phone = models.CharField(max_length=18, null=True)
|
||||
national_code = models.CharField(max_length=16)
|
||||
photo = models.CharField(max_length=50)
|
||||
birthdate = models.DateTimeField(null=True)
|
||||
nationality = models.CharField(max_length=20, null=True)
|
||||
ownership_types = (
|
||||
('N', 'Natural'),
|
||||
('L', 'Legal')
|
||||
)
|
||||
ownership = models.CharField(
|
||||
max_length=1,
|
||||
choices=ownership_types,
|
||||
default='N',
|
||||
help_text="N is natural & L is legal"
|
||||
)
|
||||
address = models.TextField(max_length=1000, null=True)
|
||||
photo = models.CharField(max_length=50, null=True)
|
||||
province = models.ForeignKey(
|
||||
'Province',
|
||||
on_delete=models.CASCADE,
|
||||
|
||||
Reference in New Issue
Block a user