registration and verify abuse WIP
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m27s

This commit is contained in:
2025-04-15 14:01:47 +05:00
parent 9f3f586181
commit e0a80d4a00
6 changed files with 100 additions and 6 deletions

View File

@ -43,6 +43,7 @@ ACCOUNT_NUMBER_PATTERN = r"^(7\d{12}|9\d{16})$"
class ErrorMessages:
USERNAME_EXISTS = "Username already exists."
MOBILE_EXISTS = "Mobile number already exists."
INVALID_ID_CARD = "Please enter a valid ID card number."
INVALID_MOBILE = "Please enter a valid mobile number."
INVALID_ACCOUNT = "Please enter a valid account number."
@ -99,12 +100,9 @@ class CreateUserView(generics.CreateAPIView):
firstname = request.data.get("firstname")
lastname = request.data.get("lastname")
# Validate required fields first
validation_error = self.validate_required_fields(request.data)
if validation_error:
return validation_error
if User.objects.filter(mobile=mobile).exists():
return Response({"message": ErrorMessages.MOBILE_EXISTS}, status=400)
# Check username uniqueness after validation
if User.objects.filter(username=username).exists():
return Response({"message": ErrorMessages.USERNAME_EXISTS}, status=400)
@ -120,6 +118,11 @@ class CreateUserView(generics.CreateAPIView):
if acc_no is None or not re.match(ACCOUNT_NUMBER_PATTERN, acc_no):
return Response({"message": ErrorMessages.INVALID_ACCOUNT}, status=400)
# Validate required fields first
validation_error = self.validate_required_fields(request.data)
if validation_error:
return validation_error
# Fetch Atoll and Island instances
try:
atoll = Atoll.objects.get(id=atoll_id)