0

I have problem about auth system. It only work by username and password, but I need use email rather than username

def login_view(request):
    if request.user.is_authenticated or request.user.is_staff or request.user.is_superuser:
        return redirect('/account/')
        elif request.method == "POST":
            email = request.POST['email']
            # username = request.POST['username'] # it work
            password = request.POST['password']
            user = authenticate(request, email=email, username=username, password=password)
        if not grecaptcha_verify(request):
            context = {'message_bad':'...'}
        elif user is not None:
            login(request, user)
            return redirect('/account/')
        else:
            context = {'message_bad':'...'}
    else:
        context = {}            
    return render(request, "login.html", context) 

Please help me or how can I change login() codes at auth lib .

1 Answers1

1

if what you have said about not having models is accurate then you will need to create a custom user model that has a custom backend where you can use the email instead of a username

id recommend following this tutorial for that https://rahmanfadhil.com/django-login-with-email/

Sirwill98
  • 324
  • 1
  • 13