Thursday, May 29, 2014

Re: Custom user model backend

Maybe try putting some logging in your CustomUserModelBackend.

Near the top, put in some logging boilerplate:

import logging
logger = logging.getLogger(__name__)

Then in your backend, something like this:

class CustomUserModelBackend(ModelBackend):
    ...
    def get_user(self, user_id):
        try:
            return self.user_class.objects.get(pk=user_id)
        except self.user_class.DoesNotExist:
            logger.info('User.id={}: User not found, attaching AnonymousUser'.format(user_id))
            return None

This backend method is checked by the AuthenticationMiddleware when it attaches the user to the request

https://github.com/django/django/blob/stable/1.6.x/django/contrib/auth/middleware.py#L18

https://github.com/django/django/blob/stable/1.6.x/django/contrib/auth/__init__.py#L133

When you make a backend like this it is also a good idea to make a test suite for it.

If these are all fruitless, maybe try looking at your session setup. I'm assuming you are running the db backend for the sessions. If you are using memcached or something else, check the usual settings (TIMEOUT, OPTIONS, etc)

K

On Wednesday, May 28, 2014 11:52:58 PM UTC-7, Domagoj Kovač wrote:
I already know about SESSION_COOKIE_AGE. I set it to be 30 minutes, but the problem is that even if i am doing something system logs me out, and this should not happen. It work properly before i implemented custom auth backend.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3bade907-e3b1-4252-b7fd-6613d87a8cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment