Пример #1
0
    def __call__(self, request):
        # Define the request.user
        request.user = get_user_from_request(request)

        request.user_is_logged = get_user_is_logged(request)
        # Preserve the user connection if it is already logged
        preserve_or_login(request)

        # Call the view
        response = self.get_response(request)

        return response
Пример #2
0
        def wrapped_function(request, *args, **kwargs):
            user = get_user_from_request(request)

            # if not AnonymousUser in user.__class__.__mro__:
            if not isinstance(user, AnonymousUser):
                if user.is_staff_user or user.is_super_user:
                    return related_function(request, *args, **kwargs)

            if if_false_html is not None:
                return render(request, if_false_html)

            else:
                return redirect(if_false_url)
Пример #3
0
    def __call__(self, request):
        # Define the request.user.
        request.user = get_user_from_request(request)

        # Add user_is_logged key in the request dict.
        user_is_logged = get_user_is_logged(request)
        request.user_is_logged = get_user_is_logged(request)

        # Preserve the user connection if it is already logged, else clean sessions.
        if user_is_logged:
            preserve_or_login(request)

        else:
            force_clear_user_session(request)

        # Call the view.
        response = self.get_response(request)

        return response
Пример #4
0
def user_context_processors(request):
    return {
        'user': get_user_from_request(request),
        'user_is_logged': get_user_is_logged(request),
    }