Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- permission_classes = [AllowAny]
- serializer_class = UserLoginSerializer
- 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) //I'm getting this response
- return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
- def validate(self, data):
- print("***************validating*******************") //This line is not being printed
- # user_obj = None
- email = data.get("email", None)
- username = data.get("username", None)
- password = data["password"]
- if not email and not username:
- raise ValidationError("A username or email is required to login.")
- user = User.objects.filter(
- Q(email=email) |
- Q(username=username)
- ).distinct()
- user = user.exclude(email__isnull=True).exclude(email__iexact='')
- print(user, "-------------*********************")
- if user.exists() and user.count() == 1:
- user_obj = user.first()
- else:
- raise ValidationError("This username/email is not valid.")
- if user_obj:
- if not user_obj.check_password(password):
- print("wrong pwd", "**************************************")
- raise ValidationError("Incorrect credentials! Please Try again!")
- data["token"] = "SOME RANDOM TOKEN"
- return data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement