*class LoginView(APIView):    # permission_classes = (AllowAny,)    def
post(self, request, format=None):        data = request.data        email =
data.get('email',None)        password = data.get('password',None)
phone_number = data.get('phone_number')        if email is not None:
    if '@' in email:                try:                    user_obj =
User.objects.filter(email__iexact = email)                    if
user_obj.exists() and user_obj.first().check_password(password):
            # user = UserLoginSerializer(user_obj)
user = authenticate(email = email, password = password)
    login(request, user)                        return
Response({"details":"login successfully"},status = status.HTTP_200_OK)
              return Response({"details":"Please signup first"},status =
status.HTTP_404_NOT_FOUND)                except User.DoesNotExist:
            return Response(status = status.HTTP_404_NOT_FOUND,deatils =
"user not found")        elif phone_number is not None:            try:
            user_obj = User.objects.filter(phone_number__iexact =
phone_number)                if user_obj.exists() and
user_obj.first().check_password(password):                    email =
user_obj[0].email                    user = authenticate(email = email,
password = password)                    login(request,user)
    return Response({"details":"login successfully"},status =
status.HTTP_200_OK)            except User.DoesNotExist:
return Response({"deatils": "user not found"},status =
status.HTTP_404_NOT_FOUND)*


*On Thu, Jan 9, 2020 at 8:42 PM Suraj Thapa FC <surajthap...@gmail.com
<surajthap...@gmail.com>> wrote:*

> *Code...? *
>
>
> *On Thu, 9 Jan 2020, 8:40 pm Soumen Khatua, <soumenkhatua...@gmail.com
> <soumenkhatua...@gmail.com>> wrote:*
>
>>
>> *Hi Folks,*
>>
>> *In django rest framework,I extend the LoginApiView(APIView) but when I'm
>> passing username and password in browser it logn successfully but in post
>> man I'm getting :*
>>
>>
>>
>> *{    "detail": "CSRF Failed: CSRF token missing or incorrect."}*
>>
>> *Do I need to use csrf_exempt inside APIView(post) request?*
>>
>> *If yes, then why it is working some times?*
>>
>> *Thank you in advance*
>>
>> *Regards,*
>> *Soumen*
>>
>>
>>
>>
>>
>> * -- You received this message because you are subscribed to the Google
>> Groups "Django users" group. To unsubscribe from this group and stop
>> receiving emails from it, send an email to
>> django-users+unsubscr...@googlegroups.com
>> <django-users+unsubscr...@googlegroups.com>. To view this discussion on the
>> web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WZC3C9WVFwGskF8uYs3pqM0fQLe9MKsqgr4FvNzxzELmw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAPUw6WZC3C9WVFwGskF8uYs3pqM0fQLe9MKsqgr4FvNzxzELmw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>> *
>
>
>
>
> * -- You received this message because you are subscribed to the Google
> Groups "Django users" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> django-users+unsubscr...@googlegroups.com
> <django-users+unsubscr...@googlegroups.com>. To view this discussion on the
> web visit
> https://groups.google.com/d/msgid/django-users/CAPjsHcEfamWnYiQbK914Y0SV2whkOXFthb3ZvOjBv2aw1-GL6A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPjsHcEfamWnYiQbK914Y0SV2whkOXFthb3ZvOjBv2aw1-GL6A%40mail.gmail.com?utm_medium=email&utm_source=footer>.*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPUw6WZt0_TRLF-ZaFrqJvbcejuqaD_DVD4Z1%2B%3DpZhAwPzT1fA%40mail.gmail.com.

Reply via email to