curl --request POST \
--url https://api.example.com/api/sign-up/ \
--header 'Content-Type: application/json' \
--data '
{
"username": "<string>",
"email": "<string>",
"password": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"number_phone": "<string>"
}
'{
"access": "<string>",
"refresh": "<string>",
"user": {
"user.id": 123,
"user.username": "<string>",
"user.email": "<string>",
"user.first_name": "<string>",
"user.last_name": "<string>",
"user.number_phone": "<string>",
"user.avatar": "<string>"
}
}Create a new user account and receive JWT authentication tokens
curl --request POST \
--url https://api.example.com/api/sign-up/ \
--header 'Content-Type: application/json' \
--data '
{
"username": "<string>",
"email": "<string>",
"password": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"number_phone": "<string>"
}
'{
"access": "<string>",
"refresh": "<string>",
"user": {
"user.id": 123,
"user.username": "<string>",
"user.email": "<string>",
"user.first_name": "<string>",
"user.last_name": "<string>",
"user.number_phone": "<string>",
"user.avatar": "<string>"
}
}Documentation Index
Fetch the complete documentation index at: https://mintlify.com/edimez14/password_generator/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/sign-up/
curl -X POST http://localhost:8000/api/sign-up/ \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "[email protected]",
"password": "SecurePass123!",
"first_name": "John",
"last_name": "Doe",
"number_phone": "5551234567"
}'
import requests
url = "http://localhost:8000/api/sign-up/"
payload = {
"username": "johndoe",
"email": "[email protected]",
"password": "SecurePass123!",
"first_name": "John",
"last_name": "Doe",
"number_phone": "5551234567"
}
response = requests.post(url, json=payload)
data = response.json()
fetch('http://localhost:8000/api/sign-up/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'johndoe',
email: '[email protected]',
password: 'SecurePass123!',
first_name: 'John',
last_name: 'Doe',
number_phone: '5551234567'
})
})
.then(response => response.json())
.then(data => console.log(data));
{
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"user": {
"id": 1,
"username": "johndoe",
"email": "[email protected]",
"first_name": "John",
"last_name": "Doe",
"number_phone": "5551234567",
"avatar": null
}
}
{
"error": "Missing required fields."
}
{
"username": ["This field is required."],
"email": ["user with this email already exists."]
}
{
"error": "Error message details"
}
apps/users/views.py:49-79. Here’s how it works:
UsersSerializeruser.set_password()RefreshToken.for_user(user)apps/users/views.py:49-79:
@api_view(['POST'])
@permission_classes([AllowAny])
def sign_up(request):
try:
serializer = UsersSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
user = Users.objects.get(username=serializer.data['username'])
user.email = serializer.data['email']
user.set_password(serializer.data['password'])
user.first_name = serializer.data['first_name']
user.last_name = serializer.data['last_name']
user.number_phone = serializer.data['number_phone']
user.save()
refresh = RefreshToken.for_user(user)
return Response({
'refresh': str(refresh),
'access': str(refresh.access_token),
'user': serializer.data
}, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except KeyError:
return Response({'error': 'Missing required fields.'}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@permission_classes([AllowAny]))AbstractUser (defined in apps/users/models.py:5)