Authenticate user using email and password

后端 未结 3 1899
我寻月下人不归
我寻月下人不归 2021-02-09 23:36

I have a form that only allow users to login via username . I decided to only allow user to login via email instead of username.

First, this is not a duplication of any

3条回答
  •  无人及你
    2021-02-09 23:57

    Looks like you are testing against 2 different fields. You look for the user against email

    if User.objects.filter(email=user).exists():
    

    but then validate against username

    user = authenticate(username=user, password=password)
    

    If you are using the email address the auth line should be

    user = authenticate(email=user, password=password)
    

提交回复
热议问题