mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-03 08:44:34 +00:00
fix signup bugs
This commit is contained in:
parent
3f47437822
commit
440ceedafa
18
core/migrations/0003_customer_name.py
Normal file
18
core/migrations/0003_customer_name.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.0 on 2025-04-13 11:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0002_alter_customer_profile_glb_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='customer',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(blank=True, max_length=255),
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,4 +4,5 @@ from ..models.customer import Customer
|
||||||
class CustomerSerializer(serializers.ModelSerializer):
|
class CustomerSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Customer
|
model = Customer
|
||||||
fields = '__all__'
|
fields = ['id','user','user_id' ,'mobile_number' , 'profile_img' , 'profile_glb' ,'is_sms_verified' , 'is_email_verified' ]
|
||||||
|
# fields = '__all__'
|
|
@ -5,4 +5,4 @@ from django.contrib.auth.models import User
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['id', 'username', 'email' , 'password' ]
|
fields = ['id' ,'first_name' , 'last_name' ]
|
||||||
|
|
|
@ -65,7 +65,7 @@ def user_has_role(user, role_name):
|
||||||
@api_view(['POST'])
|
@api_view(['POST'])
|
||||||
def signup(request):
|
def signup(request):
|
||||||
# Check if username already exists
|
# Check if username already exists
|
||||||
if User.objects.filter(username=request.data['username']).exists():
|
if User.objects.filter(username=request.data['mobile_number']).exists():
|
||||||
return Response({'username': ['A user with that username already exists.']}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({'username': ['A user with that username already exists.']}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# Ensure mobile number is provided
|
# Ensure mobile number is provided
|
||||||
|
@ -78,6 +78,9 @@ def signup(request):
|
||||||
if user_serializer.is_valid():
|
if user_serializer.is_valid():
|
||||||
user = user_serializer.save()
|
user = user_serializer.save()
|
||||||
user.set_password(request.data['password'])
|
user.set_password(request.data['password'])
|
||||||
|
user.username = request.data['mobile_number']
|
||||||
|
user.first_name = request.data['first_name']
|
||||||
|
user.last_name = request.data['last_name']
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
customer_data = {
|
customer_data = {
|
||||||
|
@ -88,7 +91,7 @@ def signup(request):
|
||||||
if customer_serializer.is_valid():
|
if customer_serializer.is_valid():
|
||||||
customer_serializer.save()
|
customer_serializer.save()
|
||||||
token = Token.objects.create(user=user)
|
token = Token.objects.create(user=user)
|
||||||
return Response({'token': token.key, 'user': customer_serializer.data}, status=status.HTTP_201_CREATED)
|
return Response({'token': token.key, 'customer': customer_serializer.data, 'user': user_serializer.data}, status=status.HTTP_201_CREATED)
|
||||||
else:
|
else:
|
||||||
# If customer data is invalid, delete the created user
|
# If customer data is invalid, delete the created user
|
||||||
user.delete()
|
user.delete()
|
||||||
|
@ -216,10 +219,23 @@ def getInfo(request):
|
||||||
customer = Customer.objects.get(user=user)
|
customer = Customer.objects.get(user=user)
|
||||||
|
|
||||||
# Serialize the customer data
|
# Serialize the customer data
|
||||||
serializer = CustomerSerializer(customer)
|
customer_serializer = CustomerSerializer(customer)
|
||||||
|
|
||||||
|
|
||||||
|
# Manually select user fields to return
|
||||||
|
user_data = {
|
||||||
|
'id': user.id,
|
||||||
|
'first_name': user.first_name,
|
||||||
|
'last_name': user.last_name,
|
||||||
|
# add any other fields you need
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response({
|
||||||
|
'customer': customer_serializer.data,
|
||||||
|
'user': user_data
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# Return the serialized customer data
|
|
||||||
return Response(serializer.data)
|
|
||||||
except Customer.DoesNotExist:
|
except Customer.DoesNotExist:
|
||||||
return Response({'error': 'No customer data found for this user'}, status=404)
|
return Response({'error': 'No customer data found for this user'}, status=404)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ Authorization: token cb8c2ef7913df31085e749398f22da5b43f419b2
|
||||||
|
|
||||||
POST http://127.0.0.1:8000/submitSmsVerification
|
POST http://127.0.0.1:8000/submitSmsVerification
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: token cb8c2ef7913df31085e749398f22da5b43f419b2
|
Authorization: token d3f1b03996140c8f7561d67221953ff704b482cb
|
||||||
|
|
||||||
{ "verification_sms_code": "807806" }
|
{ "verification_sms_code": "807806" }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user