email = request.data.get('email').lower(
).strip() if 'email' in request.data else None
password = request.data['password'] if 'password' in request.data else None
if not email or not password:
return Response({"success": False, 'response': {'message': 'Invalid data.'
}},
status=status.HTTP_400_BAD_REQUEST)
try:
user = User.objects.get(email=email).username
except:
return Response({"success": False, 'response': {'message': 'Incorrect User
Credentials!'}},
status=status.HTTP_404_NOT_FOUND)
try:
user = User.objects.get(email=email is_active=True).username
except:
return Response({"success": False, 'response': {'message': 'Sorry! Your
account is not active!'}},
status=status.HTTP_400_BAD_REQUEST)
user = authenticate(username=user, password=password)

On Fri, 12 Aug 2022, 8:34 am Abhishek Chauhan, <[email protected]> wrote:

> Use custom user model and override username to email
>
> On Fri, 12 Aug 2022 at 9:03 AM, Suraj Singh <[email protected]>
> wrote:
>
>> Kindly help me to solve this issue, posted it in django forum,
>>
>>
>> https://forum.djangoproject.com/t/how-to-change-the-default-username-to-email-in-drf-obtain-token-login/15383
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-rest-framework/ce9f65f7-d666-4479-b486-76f2f95f583fn%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-rest-framework/ce9f65f7-d666-4479-b486-76f2f95f583fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> *Abhishek Chauhan*
>
> ✆ : 9560 432 275
>
>  *@abhiazh* <https://twitter.com/abhiazh>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/CAOaWsMFR8nqvzVpiq9L153hvqmW9X5Z6WVuVfq%2BjnPVAkVP_Bw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-rest-framework/CAOaWsMFR8nqvzVpiq9L153hvqmW9X5Z6WVuVfq%2BjnPVAkVP_Bw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CABNyTSreLYhJjX2ky%2BR4swCNkZrXg%3DU6kTn%3DP_BCN5FOUffXXg%40mail.gmail.com.

Reply via email to