コード例 #1
0
def remember_user(request, user):
    """Set the remember-me flag on the user.

    A token is automatically generated and stored in the user's session.
    This token is set as a cookie value by the middleware.

    """
    token_string = create_token_string(user, None)
    preset_cookie(request, token_string)
コード例 #2
0
    def authenticate(self, token_string, request):
        """Return the user associated with the given token."""
        token = RememberToken.objects.get_by_string(token_string)
        if not token:
            return
        user = token.user

        # Create new token cookie value and delete current token
        token_string = utils.create_token_string(user, token)
        utils.preset_cookie(request, token_string)
        token.delete()

        user._auth_remember_user = True
        return user
コード例 #3
0
    def process_request(self, request):
        if request.user.is_authenticated():
            request.user.is_fresh = request.session.get(SESSION_KEY, False)
            return

        request.user.is_fresh = False

        token = request.COOKIES.get(COOKIE_NAME, None)
        if not token:
            return
        user = django_auth.authenticate(token_string=token)

        # since the token changes on each login, we need to update the cookie
        if hasattr(user, '_auth_remember_token'):
            utils.preset_cookie(request, user._auth_remember_token)
            delattr(user, '_auth_remember_token')

        if user:
            user._auth_remember_user = True
            django_auth.login(request, user)
コード例 #4
0
def remove_auth_remember(sender, **kwargs):
    utils.preset_cookie(kwargs['request'], '')
コード例 #5
0
def remove_auth_remember(sender, **kwargs):
    utils.preset_cookie(kwargs['request'], '')