authentication - django-registration custom backend -


i have implemented auth/login custom backend, , trying implement own django-registration custom backend. django-registration code seems work fine, if use normal authentication contrib.auth . if not (in case want use own newly created custom authentication)

user object has no attribute backend

.

my registration backend:

from django.conf import settings #from django.contrib.auth import authenticate django.contrib.auth import login  registration import signals registration.forms import registrationform class myregistrationbackend(object):      def register(self, request, **kwargs):         """         create , log in new user.          """         print "debug"         username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']         user.objects.create_user(username, email, password)          # authenticate() has called before login(), ,         # return user created.          auth = myauthbackend()          new_user = auth.authenticate(username=username, password=password)         login(request, new_user)         signals.user_registered.send(sender=self.__class__,                                      user=new_user,                                      request=request)         return new_user 

then auth backend:

class myauthbackend(object):     """     authenticates against django.contrib.auth.models.user. modifications     """     supports_inactive_user = true      """     function not upgrade user password hasher     """     def check_password(self,password, encoded):         if not password or not is_password_usable(encoded):             return false          password = smart_str(password)         encoded = smart_str(encoded)          if encoded[0] == "$":             encoded = encoded[1:]   #make compatible drupal 7 sha512 hasher can work          if len(encoded) == 32 , '$' not in encoded:             hasher = get_hasher('unsalted_md5')         else:             algorithm = encoded.split('$', 1)[0]                       hasher = get_hasher(algorithm)          is_correct = hasher.verify(password, encoded)          return is_correct      def authenticate(self, username=none, password=none):         try:             user = user.objects.get(username=username)             if self.check_password(password, user.password):                 return user         except user.doesnotexist:             return none 

any ideas?? believe maybe instantiating auth = myauthbackend() wrong way.. or maybe else

try setting authentication_backends setting described in docs on specifying authentication backends

then, in register method, use django.contrib.auth.authenticate method log in (see how log user in) instead of instantiating instance of backend manually. authenticate method should take care of setting user backend attribute, shouldn't errors.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -