def post(self, request): req_data = request.data login_serializer = UserLoginSerializer(data=req_data) login_serializer.is_valid(raise_exception=True) # if no validation error # logging in the user user = authenticate(email=req_data.get('email'), password=req_data.get('password')) login(request, user) return Response(data=login_serializer.data, status=status.HTTP_200_OK)
def post(self, request, *args, **kwargs): data = request.data serializer = UserLoginSerializer(data=data) if serializer.is_valid(raise_exception=True): new_data = serializer.data return Response(new_data, status=HTTP_200_OK) return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kwargs): data = request.data serializer = UserLoginSerializer(data=data) if serializer.is_valid(raise_exception=True): username = serializer.data['username'] user = User.objects.filter(username=username).first() token = Token.objects.filter(user=user).first().key return Response({'token': token}, status=HTTP_200_OK) return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
def post(self, request, format='json'): data = request.data serializer = UserLoginSerializer(data=data) if serializer.is_valid(): user = serializer.validated_data['user'] login(request, user) token, create = Token.objects.get_or_create(user=user) print(token) return Response({"token":token.key}, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None, *args, **kwargs): data = request.data serializer = UserLoginSerializer(data=data) if serializer.is_valid(raise_exception=True): new_data = serializer.data kwargs = { 'username': new_data['username'], 'password': new_data['password'], } user = auth.authenticate(**kwargs) extra_data = {} auth.login(request, user) token, _ = Token.objects.get_or_create(user=user) extra_data['token'] = token.key return Response(extra_data, status=HTTP_200_OK) return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kwargs): serialized_data = UserLoginSerializer(data=request.data) if serialized_data.is_valid(): user = auth.authenticate(request, **serialized_data.data) if user is not None: auth.login(request, user) user_serialized = UserSerializer(user) return Response(data=user_serialized.data, status=status.HTTP_200_OK) return Response(data={'message': 'invalid credentials'}, status=status.HTTP_404_NOT_FOUND) return Response( data={'message': 'initial credential validation failed'}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): response_data = {} serializer = UserLoginSerializer(data=request.data) if serializer.is_valid(raise_exception=True): user = serializer.validated_data['user'] token, created = Token.objects.get_or_create(user=user) user_logged_in.send(sender=user.__class__, request=request, user=user) update_last_login(None, user) response_data['details'] = 'successfully logged in' # response_data['email'] = user.email # response_data['fullname'] = user.fullname # response_data['username'] = user.username # response_data['avatar'] = request.build_absolute_uri(user.avatar.url) #response_data['pk'] = user.pk response_data['token'] = token.key else: response_data = serializer.errors return Response(response_data)
def post(self,request): serializer=UserLoginSerializer(data=request.data) serializer.is_valid(raise_exception=True) user = serializer.validated_data['user'] token, created = Token.objects.get_or_create(user=user) return Response({'token': token.key},status=status.HTTP_200_OK)
def post(self, request, *args, **kwargs): serializer = UserLoginSerializer(data=request.data) serializer.is_valid(raise_exception=True) token = serializer.save() data = {'status': 'ok', 'token': token} return Response(data, status=status.HTTP_201_CREATED)
def post(self, request): req_data = request.data login_serializer = UserLoginSerializer(data=req_data) login_serializer.is_valid(raise_exception=True) return Response(data=login_serializer.data, status=status.HTTP_200_OK)