当前位置: 首页>>代码示例>>Python>>正文


Python auth.SESSION_KEY属性代码示例

本文整理汇总了Python中django.contrib.auth.SESSION_KEY属性的典型用法代码示例。如果您正苦于以下问题:Python auth.SESSION_KEY属性的具体用法?Python auth.SESSION_KEY怎么用?Python auth.SESSION_KEY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.contrib.auth的用法示例。


在下文中一共展示了auth.SESSION_KEY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_load_modified

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_load_modified(store, django_user_model):
    django_user_model.objects.create_user(username="test_user")

    store[auth.SESSION_KEY] = 1
    store.save()
    store2 = SessionStore(session_key=store.session_key, user_agent="TestUA/1.1-changed", ip="8.8.8.8")
    store2.load()
    assert store2.get(USER_AGENT_SESSION_KEY) == "TestUA/1.1"
    assert store2.get(IP_SESSION_KEY) == "127.0.0.1"
    assert store2.get(auth.SESSION_KEY) == 1
    assert store2.modified is True

    store2.save()

    assert store2.get(USER_AGENT_SESSION_KEY) == "TestUA/1.1-changed"
    assert store2.get(IP_SESSION_KEY) == "8.8.8.8" 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:18,代码来源:test_sessionstore.py

示例2: get_cached_user

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def get_cached_user(request):
    if not hasattr(request, '_cached_user'):
        try:
            key = CACHE_KEY.format(request.session[SESSION_KEY])
            cache = caches['default']
            user = cache.get(key)
        except KeyError:
            user = AnonymousUser()
        if user is None:
            user = get_user(request)
            cache = caches['default']
            # 8 hours
            cache.set(key, user, 28800)
            logger.debug('No User Cache. Setting now: {0}, {1}'.format(key, user.username))
        request._cached_user = user
    return request._cached_user 
开发者ID:dkarchmer,项目名称:django-aws-template,代码行数:18,代码来源:middleware.py

示例3: create_users

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import 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

示例4: test_login_with_u2f

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_login_with_u2f(self):
        code = self.enable_backupcode()
        r = self.client.post(self.login_url, {
            'username': 'test',
            'password': 'asdfasdf',
        })
        self.assertNotIn(SESSION_KEY, self.client.session)
        self.assertIn(reverse('u2f:verify-second-factor'), r['location'])

        verify_key_response = self.client.get(r['location'])
        self.assertContains(verify_key_response, 'Django administration')

        r = self.client.post(r['location'], {
            'code': code,
            'type': 'backup',
        })

        self.assertEqual(str(self.client.session[SESSION_KEY]), str(self.user.id))
        self.assertTrue(r['location'].endswith(self.admin_url)) 
开发者ID:gavinwahl,项目名称:django-u2f,代码行数:21,代码来源:tests.py

示例5: test_login_while_already_logged_in

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_login_while_already_logged_in(self):
        User.objects.create_superuser(
            username='test2',
            email='test2@example.com',
            password='asdfasdf',
        )
        r = self.client.post(self.login_url, {
            'username': 'test2',
            'password': 'asdfasdf',
            'next': '/next/'
        })
        assert r.status_code == 302

        code = self.enable_backupcode()
        r = self.login()
        self.assertIn(reverse('u2f:verify-second-factor'), r['location'])

        r = self.client.post(r['location'], {
            'code': code,
            'type': 'backup',
        })
        self.assertEqual(str(self.client.session[SESSION_KEY]), str(self.user.id))
        self.assertTrue(r['location'].endswith('/next/'))
        self.assertFalse(self.user.backup_codes.filter(code=code).exists()) 
开发者ID:gavinwahl,项目名称:django-u2f,代码行数:26,代码来源:tests.py

示例6: test_token_cant_be_used_twice

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_token_cant_be_used_twice(self):
        key = self.enable_totp()
        r = self.login()
        token = oath.totp(key, timezone.now()),
        r = self.client.post(r['location'], {
            'token': token,
            'type': 'totp',
        })
        self.assertEqual(str(self.client.session[SESSION_KEY]), str(self.user.id))
        self.client.logout()
        r = self.login()
        r = self.client.post(r['location'], {
            'token': token,
            'type': 'totp',
        })
        self.assertContains(r, TOTPForm.INVALID_ERROR_MESSAGE) 
开发者ID:gavinwahl,项目名称:django-u2f,代码行数:18,代码来源:tests.py

示例7: getUserFromSessionId

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import 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

示例8: test_auth_session_key

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_auth_session_key(store):
    assert auth.SESSION_KEY not in store
    assert store.modified is False
    assert store.accessed is True

    store.get(auth.SESSION_KEY)
    assert store.modified is False

    store[auth.SESSION_KEY] = 1
    assert store.modified is True 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:12,代码来源:test_sessionstore.py

示例9: test_save

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_save(store, django_user_model):
    django_user_model.objects.create_user(username="test_user")

    store[auth.SESSION_KEY] = 1
    store.save()

    session = Session.objects.get(pk=store.session_key)
    assert session.user_agent == "TestUA/1.1"
    assert session.ip == "127.0.0.1"
    assert session.user_id == 1
    assert now() - timedelta(seconds=5) <= session.updated_at <= now() 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:13,代码来源:test_sessionstore.py

示例10: test_load_unmodified

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_load_unmodified(store, django_user_model):
    django_user_model.objects.create_user(username="test_user")

    store[auth.SESSION_KEY] = 1
    store.save()
    store2 = SessionStore(session_key=store.session_key, user_agent="TestUA/1.1", ip="127.0.0.1")
    store2.load()
    assert store2.get(USER_AGENT_SESSION_KEY) == "TestUA/1.1"
    assert store2.get(IP_SESSION_KEY) == "127.0.0.1"
    assert store2.get(auth.SESSION_KEY) == 1
    assert store2.modified is False 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:13,代码来源:test_sessionstore.py

示例11: test_clear

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_clear(store):
    """
    Clearing the session should clear all non-browser information
    """
    store[auth.SESSION_KEY] = 1
    store.clear()
    store.save()

    session = Session.objects.get(pk=store.session_key)
    assert session.user_id is None 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:12,代码来源:test_sessionstore.py

示例12: test_get_decoded

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def test_get_decoded(django_user_model):
    django_user_model.objects.create_user(username="test_user")

    store = SessionStore(user_agent="TestUA/1.1", ip="127.0.0.1")
    store[auth.SESSION_KEY] = 1
    store["foo"] = "bar"
    store.save()

    session = Session.objects.get(pk=store.session_key)
    assert session.get_decoded() == {
        "foo": "bar",
        auth.SESSION_KEY: 1,
        IP_SESSION_KEY: "127.0.0.1",
        USER_AGENT_SESSION_KEY: "TestUA/1.1",
    } 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:17,代码来源:test_model.py

示例13: create_model_instance

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def create_model_instance(self, data):
        # Store User, User Agent, and IP in Session (in DB).
        return self.model(
            session_key=self._get_or_create_session_key(),
            session_data=self.encode(data),
            expire_date=self.get_expiry_date(),
            user_id=self.get(auth.SESSION_KEY),
            user_agent=self.user_agent,
            ip=self.ip,
        ) 
开发者ID:QueraTeam,项目名称:django-qsessions,代码行数:12,代码来源:db.py

示例14: get_session_dict_user

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def get_session_dict_user(session_dict: Mapping[str, int]) -> Optional[int]:
    # Compare django.contrib.auth._get_user_session_key
    try:
        return get_user_model()._meta.pk.to_python(session_dict[SESSION_KEY])
    except KeyError:
        return None 
开发者ID:zulip,项目名称:zulip,代码行数:8,代码来源:sessions.py

示例15: __setitem__

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import SESSION_KEY [as 别名]
def __setitem__(self, key, value):
        if key == auth.SESSION_KEY:
            self.user_id = value
        super(SessionStore, self).__setitem__(key, value) 
开发者ID:AcaciaTrading,项目名称:acacia_main,代码行数:6,代码来源:db.py


注:本文中的django.contrib.auth.SESSION_KEY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。