def registration(request): if request.method == 'POST': user_data = request.data serializer = RegisterSerializer(data=user_data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data, status=HTTP_201_CREATED)
def post(self, request): serializer = RegisterSerializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return response.Response( status=status.HTTP_201_CREATED, data=serializer.data, )
def register(request): if request.method == 'POST': data = JSONParser().parse(request) username = data['email'].split('@')[0] data['username'] = username serializer = RegisterSerializer(data=data) if serializer.is_valid(): serializer.save() Response = { "id": serializer.data['id'], "token": serializer.data['token'] } return JsonResponse(Response) return HttpResponse(status=404)
def register(request): serializer = RegisterSerializer(data=request.data) serializer.is_valid(raise_exception=True) user = serializer.save() return Response({ "message": "User Created Successfully. Now perform Login to get your token", })
def post(self, request): serializer = RegisterSerializer(data=request.data) data = {} if serializer.is_valid(): person = serializer.save() data['response'] = ['success'] else: data = serializer.errors return Response(data)
def post(self, request): # Save our code and return the serialized data. serializer = RegisterSerializer(data=request.data) serializer.is_valid(raise_exception=True) data = serializer.save() # Get the newly created user from the registration. authenticated_user = data['user'] # Get our web application authorization. application = Application.objects.filter( name=settings.MIKAID_RESOURCE_SERVER_NAME).first() # Generate our access token which does not have a time limit. aware_dt = timezone.now() expires_dt = aware_dt.replace(aware_dt.year + 1776) access_token, created = AccessToken.objects.update_or_create( application=application, user=authenticated_user, defaults={ 'user': authenticated_user, 'application': application, 'expires': expires_dt, 'token': generate_token(), 'scope': 'read,write,introspection' }, scope='read,write,introspection') # Return our new token. return Response( data={ # --- REQUIRED --- # 'token': str(access_token), 'scope': access_token.scope, # --- OPTIONAL --- # "client_id": access_token.user.id, "email": access_token.user.email, # "exp": int(format(access_token.expires, 'U')) "exp": access_token.expires, }, status=status.HTTP_201_CREATED)
def post(self, request, format=None): serializer = RegisterSerializer(data=request.data) if serializer.is_valid(): token = serializer.save() return Response({'token': token}, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)