﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27527	How to enable login for a custom written authentication backend	Kireeti	nobody	"Hello Django Team, Thanks for creating such powerful framework and making it open. For one of my projects i wanted to let users login with OTP, for which i am doing the verification manually. I want to use the login() to let the user login to his account, order products. For which i created my own backend to query the model with the phone number all this part until authenticate is working fine. but i am not able to figure out how to use login from here.  below is a snippet of what i created.

Backend:

from .models import Customer

class CustomerModelBackend(object):
    def authenticate(self, phone_number=None, password=None):
        try:
            user = Customer.objects.get(phone=phone_number)
            if user is not None:
                return user
            else:
                return False
        except user.DoesNotExist:
            return False

    def get_user(self, phone):
        try:
            return Customer.objects.get(pk=phone)
        except Customer.DoesNotExist:
            return None

Views.py
customer_backend = CustomerModelBackend()
customer_exist = customer_backend.authenticate(phone_number=phone)
login(request, customer_exist)

Here customer_exist is getting customer object as expected but login function is throwing global name not defined. importing login from contrib/auth is throwing backend not defined. 

Someone please advice what to do.

Thanks."	Uncategorized	new	contrib.auth	1.9	Release blocker		Authenticate, Login, Backend		Unreviewed	0	0	0	0	0	0
