當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。