當前位置: 首頁>>代碼示例>>Python>>正文


Python auth.BACKEND_SESSION_KEY屬性代碼示例

本文整理匯總了Python中django.contrib.auth.BACKEND_SESSION_KEY屬性的典型用法代碼示例。如果您正苦於以下問題:Python auth.BACKEND_SESSION_KEY屬性的具體用法?Python auth.BACKEND_SESSION_KEY怎麽用?Python auth.BACKEND_SESSION_KEY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.contrib.auth的用法示例。


在下文中一共展示了auth.BACKEND_SESSION_KEY屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_refreshable_url

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def is_refreshable_url(self, request):
        """Takes a request and returns whether it triggers a refresh examination

        :arg HttpRequest request:

        :returns: boolean

        """
        # Do not attempt to refresh the session if the OIDC backend is not used
        backend_session = request.session.get(BACKEND_SESSION_KEY)
        is_oidc_enabled = True
        if backend_session:
            auth_backend = import_string(backend_session)
            is_oidc_enabled = issubclass(auth_backend, OIDCAuthenticationBackend)

        return (
            request.method == 'GET' and
            request.user.is_authenticated and
            is_oidc_enabled and
            request.path not in self.exempt_urls
        ) 
開發者ID:mozilla,項目名稱:mozilla-django-oidc,代碼行數:23,代碼來源:middleware.py

示例2: create_users

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def create_users(self):
        for username in self.get_my_usernames():
            user = User.objects.create(username=username)
            user.set_password('p4ssw0rd')
            user.save()
            profile = user.get_profile()
            profile.has_seen_sheet_page = True
            profile.save()

            # create sessions we can use for login too
            session = SessionStore()
            session[SESSION_KEY] = user.pk
            session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
            session[HASH_SESSION_KEY] = user.get_session_auth_hash()
            session.save()
            self.session_keys[username] = session.session_key 
開發者ID:pythonanywhere,項目名稱:dirigible-spreadsheet,代碼行數:18,代碼來源:functionaltest.py

示例3: clean_username

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def clean_username(self, username, request):
        """
        Allows the backend to clean the username, if the backend defines a
        clean_username method.
        """
        backend_str = request.session[auth.BACKEND_SESSION_KEY]
        backend = auth.load_backend(backend_str)
        try:
            LOGGER.debug(
                _('calling the backend {0} clean_username with {1}'),
                backend,
                username)
            username = backend.clean_username(username)
            LOGGER.debug(_('cleaned username is {0}'), username)
        except AttributeError:  # Backend has no clean_username method.
            pass
        return username 
開發者ID:abelardopardo,項目名稱:ontask_b,代碼行數:19,代碼來源:middleware.py

示例4: clean_username

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def clean_username(self, username, request):
        """
        Allows the backend to clean the username, if the backend defines a
        clean_username method.
        """
        backend_str = request.session[auth.BACKEND_SESSION_KEY]
        backend = auth.load_backend(backend_str)
        try:
            LOGGER.debug('calling the backend %s clean_username with %s',
                         backend,
                         username)
            username = backend.clean_username(username)
            LOGGER.debug('cleaned username is %s', username)
        except AttributeError:  # Backend has no clean_username method.
            pass
        return username 
開發者ID:abelardopardo,項目名稱:ontask_b,代碼行數:18,代碼來源:middleware_patched.py

示例5: getUserFromSessionId

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def getUserFromSessionId(self, session_id):
        """Return the user from `session_id`."""
        session_engine = self.factory.getSessionEngine()
        session_wrapper = session_engine.SessionStore(session_id)
        user_id = session_wrapper.get(SESSION_KEY)
        backend = session_wrapper.get(BACKEND_SESSION_KEY)
        if backend is None:
            return None
        auth_backend = load_backend(backend)
        if user_id is not None and auth_backend is not None:
            user = auth_backend.get_user(user_id)
            # Get the user again prefetching the SSHKey for the user. This is
            # done so a query is not made for each action that is possible on
            # a node in the node listing.
            return (
                User.objects.filter(id=user.id)
                .prefetch_related("sshkey_set")
                .first()
            )
        else:
            return None 
開發者ID:maas,項目名稱:maas,代碼行數:23,代碼來源:protocol.py

示例6: clean_username

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def clean_username(self, username, request):
        """
        Allows the backend to clean the username, if the backend defines a
        clean_username method.
        """
        backend_str = request.session[auth.BACKEND_SESSION_KEY]
        backend = auth.load_backend(backend_str)
        try:
            username = backend.clean_username(username)
        except AttributeError:  # Backend has no clean_username method.
            pass
        return username 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:14,代碼來源:middleware.py

示例7: _remove_invalid_user

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:middleware.py

示例8: clean_username

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def clean_username(self, username, request):
        """
        Allow the backend to clean the username, if the backend defines a
        clean_username method.
        """
        backend_str = request.session[auth.BACKEND_SESSION_KEY]
        backend = auth.load_backend(backend_str)
        try:
            username = backend.clean_username(username)
        except AttributeError:  # Backend has no clean_username method.
            pass
        return username 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:14,代碼來源:middleware.py

示例9: _remove_invalid_user

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
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) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:middleware.py

示例10: _is_cas_backend

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def _is_cas_backend(session):
    """ Checks if the auth backend is CASBackend """
    backend = session.get(BACKEND_SESSION_KEY)
    from django_cas.backends import CASBackend
    return backend == '{0.__module__}.{0.__name__}'.format(CASBackend) 
開發者ID:childe,項目名稱:esproxy,代碼行數:7,代碼來源:models.py

示例11: get_user

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def get_user(scope):
    """
    Return the user model instance associated with the given scope.
    If no user is retrieved, return an instance of `AnonymousUser`.
    """
    if "session" not in scope:
        raise ValueError("Cannot find session in scope. You should wrap your consumer in SessionMiddleware.")
    user = None
    session = scope["session"]
    with scope["tenant"]:
        try:
            user_id = _get_user_session_key(session)
            backend_path = session[BACKEND_SESSION_KEY]
        except KeyError:
            pass
        else:
            if backend_path in settings.AUTHENTICATION_BACKENDS:
                backend = load_backend(backend_path)
                user = backend.get_user(user_id)
                # Verify the session
                if hasattr(user, "get_session_auth_hash"):
                    session_hash = session.get(HASH_SESSION_KEY)
                    session_hash_verified = session_hash and constant_time_compare(
                        session_hash, user.get_session_auth_hash()
                    )
                    if not session_hash_verified:
                        session.flush()
                        user = None
    return user or AnonymousUser() 
開發者ID:lorinkoz,項目名稱:django-pgschemas,代碼行數:31,代碼來源:auth.py

示例12: shortcut_login

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def shortcut_login(self, **credentials):
        user = authenticate(**credentials)
        if not user:
            raise ValueError("User {0} was not authenticated".format(user))

        session_auth_hash = ''
        if hasattr(user, 'get_session_auth_hash'):
            session_auth_hash = user.get_session_auth_hash()

        # Mimicking django.contrib.auth functionality
        self.set_session_data({AUTH_ID_SESSION_KEY: user.pk,
                               AUTH_HASH_SESSION_KEY: session_auth_hash,
                               AUTH_BACKEND_SESSION_KEY: user.backend}) 
開發者ID:django-functest,項目名稱:django-functest,代碼行數:15,代碼來源:utils.py

示例13: shortcut_logout

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def shortcut_logout(self):
        self.set_session_data({AUTH_BACKEND_SESSION_KEY: ''}) 
開發者ID:django-functest,項目名稱:django-functest,代碼行數:4,代碼來源:utils.py

示例14: form_valid

# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import BACKEND_SESSION_KEY [as 別名]
def form_valid(self, form):
        # OTPTokenForm does not call authenticate(), so we may need to populate
        # user.backend ourselves to keep login() happy.
        user = form.get_user()
        if not hasattr(user, 'backend'):
            user.backend = self.request.session[BACKEND_SESSION_KEY]

        return super().form_valid(form)


# Backwards compatibility. 
開發者ID:django-otp,項目名稱:django-otp,代碼行數:13,代碼來源:views.py


注:本文中的django.contrib.auth.BACKEND_SESSION_KEY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。