#27527: How to enable login for a custom written authentication backend
-------------------------------------+-------------------------------------
               Reporter:  Kireeti    |          Owner:  nobody
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  1.9
  contrib.auth                       |
               Severity:  Release    |       Keywords:  Authenticate,
  blocker                            |  Login, Backend
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27527>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.bc598f99577663a2fe7973c316337d05%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to