Python django.contrib.auth.backends.RemoteUserBackend() Examples

The following are 6 code examples of django.contrib.auth.backends.RemoteUserBackend(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.auth.backends , or try the search function .
Example #1
Source File: test_remote_user_deprecation.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_configure_user_deprecation_warning(self):
        """
        A deprecation warning is shown for RemoteUserBackend that have a
        configure_user() method without a request parameter.
        """
        num_users = User.objects.count()
        with warnings.catch_warnings(record=True) as warns:
            warnings.simplefilter('always')
            response = self.client.get('/remote_user/', **{self.header: 'newuser'})
            self.assertEqual(response.context['user'].username, 'newuser')
        self.assertEqual(len(warns), 1)
        self.assertEqual(
            str(warns[0].message),
            'Update CustomRemoteUserBackend.configure_user() to accept '
            '`request` as the first argument.'
        )
        self.assertEqual(User.objects.count(), num_users + 1)
        user = User.objects.get(username='newuser')
        self.assertEqual(user.email, 'user@example.com') 
Example #2
Source File: middleware.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def _remove_invalid_user(self, request):
        """
        Removes the current authenticated user in the request which is invalid
        but only if the user is authenticated via the RemoteUserBackend.
        """
        try:
            stored_backend = load_backend(request.session.get(auth.BACKEND_SESSION_KEY, ''))
        except ImportError:
            # backend failed to load
            auth.logout(request)
        else:
            if isinstance(stored_backend, RemoteUserBackend):
                auth.logout(request) 
Example #3
Source File: middleware.py    From bioforum with MIT License 5 votes vote down vote up
def _remove_invalid_user(self, request):
        """
        Remove the current authenticated user in the request which is invalid
        but only if the user is authenticated via the RemoteUserBackend.
        """
        try:
            stored_backend = load_backend(request.session.get(auth.BACKEND_SESSION_KEY, ''))
        except ImportError:
            # backend failed to load
            auth.logout(request)
        else:
            if isinstance(stored_backend, RemoteUserBackend):
                auth.logout(request) 
Example #4
Source File: middleware.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def _remove_invalid_user(self, request):
        """
        Remove the current authenticated user in the request which is invalid
        but only if the user is authenticated via the RemoteUserBackend.
        """
        try:
            stored_backend = load_backend(request.session.get(auth.BACKEND_SESSION_KEY, ''))
        except ImportError:
            # backend failed to load
            auth.logout(request)
        else:
            if isinstance(stored_backend, RemoteUserBackend):
                auth.logout(request) 
Example #5
Source File: middleware.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def _remove_invalid_user(self, request):
        """
        Removes the current authenticated user in the request which is invalid
        but only if the user is authenticated via the RemoteUserBackend.
        """
        try:
            stored_backend = load_backend(request.session.get(auth.BACKEND_SESSION_KEY, ''))
        except ImportError:
            # backend failed to load
            auth.logout(request)
        else:
            if isinstance(stored_backend, RemoteUserBackend):
                auth.logout(request) 
Example #6
Source File: middleware.py    From python2017 with MIT License 5 votes vote down vote up
def _remove_invalid_user(self, request):
        """
        Removes the current authenticated user in the request which is invalid
        but only if the user is authenticated via the RemoteUserBackend.
        """
        try:
            stored_backend = load_backend(request.session.get(auth.BACKEND_SESSION_KEY, ''))
        except ImportError:
            # backend failed to load
            auth.logout(request)
        else:
            if isinstance(stored_backend, RemoteUserBackend):
                auth.logout(request)