当前位置: 首页>>代码示例>>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;未经允许,请勿转载。