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


Python user.User类代码示例

本文整理汇总了Python中gittip.security.user.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: outbound

def outbound(response):
    if 'user' in response.request.context:
        user = response.request.context['user']
        if not isinstance(user, User):
            raise Response(400, "If you define 'user' in a simplate it has to "
                                "be a User instance.")
    else:
        user = User()

    if user.ANON: # user is anonymous
        if 'session' not in response.request.headers.cookie:
            # no cookie in the request, don't set one on response
            return
        else:
            # expired cookie in the request, instruct browser to delete it
            response.headers.cookie['session'] = ''
            expires = 0
    else: # user is authenticated
        response.headers['Expires'] = BEGINNING_OF_EPOCH # don't cache
        response.headers.cookie['session'] = user.participant.session_token
        expires = time.time() + TIMEOUT
        user.keep_signed_in_until(expires)

    cookie = response.headers.cookie['session']
    # I am not setting domain, because it is supposed to default to what we
    # want: the domain of the object requested.
    #cookie['domain']
    cookie['path'] = '/'
    cookie['expires'] = rfc822.formatdate(expires)
    cookie['httponly'] = "Yes, please."
    if gittip.canonical_scheme == 'https':
        cookie['secure'] = "Yes, please."
开发者ID:abnor,项目名称:www.gittip.com,代码行数:32,代码来源:authentication.py

示例2: test_user_can_be_loaded_from_session_token

 def test_user_can_be_loaded_from_session_token(self):
     self.make_participant('alice')
     user = User.from_username('alice')
     user.sign_in()
     token = user.participant.session_token
     actual = User.from_session_token(token).participant.username
     assert actual == 'alice'
开发者ID:Aaron1011,项目名称:www.gittip.com,代码行数:7,代码来源:test_user.py

示例3: inbound

def inbound(request):
    """Authenticate from a cookie or an API key in basic auth.
    """
    user = None
    if 'Authorization' in request.headers:
        header = request.headers['authorization']
        if header.startswith('Basic '):
            creds = header[len('Basic '):].decode('base64')
            token, ignored = creds.split(':')
            user = User.from_api_key(token)

            # We don't require CSRF if they basically authenticated.
            csrf_token = csrf._get_new_csrf_key()
            request.headers.cookie['csrf_token'] = csrf_token
            request.headers['X-CSRF-TOKEN'] = csrf_token
            if 'Referer' not in request.headers:
                request.headers['Referer'] = \
                                        'https://%s/' % csrf._get_host(request)
    elif 'session' in request.headers.cookie:
        token = request.headers.cookie['session'].value
        user = User.from_session_token(token)

    if user is None:
        user = User()
    request.context['user'] = user
开发者ID:abnor,项目名称:www.gittip.com,代码行数:25,代码来源:authentication.py

示例4: test_user_from_expired_session_is_anonymous

 def test_user_from_expired_session_is_anonymous(self):
     self.make_participant('alice')
     user = User.from_username('alice')
     user.sign_in(SimpleCookie())
     token = user.participant.session_token
     user.participant.set_session_expires(utcnow())
     user = User.from_session_token(token)
     assert user.ANON
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:8,代码来源:test_user.py

示例5: serve_request

def serve_request(path, user=None):
    """Given an URL path, return response.
    """
    request = StubRequest(path)
    request.website = test_website
    if user is not None:
        user = User.from_username(user)
        # Note that Cookie needs a bytestring.
        request.headers.cookie[str('session')] = user.session_token
    response = test_website.handle_safely(request)
    return response
开发者ID:balupton,项目名称:www.gittip.com,代码行数:11,代码来源:__init__.py

示例6: test_session_cookie_is_secure_if_it_should_be

 def test_session_cookie_is_secure_if_it_should_be(self):
     canonical_scheme = gittip.canonical_scheme
     gittip.canonical_scheme = 'https'
     try:
         cookies = SimpleCookie()
         self.make_participant('alice')
         user = User.from_username('alice')
         user.sign_in(cookies)
         assert '; secure' in cookies[SESSION].output()
     finally:
         gittip.canonical_scheme = canonical_scheme
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:11,代码来源:test_user.py

示例7: test_session_is_regularly_refreshed

 def test_session_is_regularly_refreshed(self):
     self.make_participant('alice')
     user = User.from_username('alice')
     user.sign_in(SimpleCookie())
     cookies = SimpleCookie()
     user.keep_signed_in(cookies)
     assert SESSION not in cookies
     cookies = SimpleCookie()
     expires = user.participant.session_expires
     user.participant.set_session_expires(expires - SESSION_REFRESH)
     user.keep_signed_in(cookies)
     assert SESSION in cookies
开发者ID:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:12,代码来源:test_user.py

示例8: perform_request

    def perform_request(self, request, user):
        request.website = test_website
        if user is not None:
            user = User.from_username(user)
            user.sign_in()
            # Note that Cookie needs a bytestring.
            request.headers.cookie[str('session')] = \
                                                 user.participant.session_token

        response = test_website.handle_safely(request)
        if response.headers.cookie:
            self.cookies.update(response.headers.cookie)
        return response
开发者ID:angleman,项目名称:www.gittip.com,代码行数:13,代码来源:client.py

示例9: inbound

def inbound(request):
    """Authenticate from a cookie or an API key in basic auth.
    """
    user = None
    if request.line.uri.startswith("/assets/"):
        pass
    elif "Authorization" in request.headers:
        header = request.headers["authorization"]
        if header.startswith("Basic "):
            creds = header[len("Basic ") :].decode("base64")
            token, ignored = creds.split(":")
            user = User.from_api_key(token)

            # We don't require CSRF if they basically authenticated.
            csrf_token = csrf._get_new_csrf_key()
            request.headers.cookie["csrf_token"] = csrf_token
            request.headers["X-CSRF-TOKEN"] = csrf_token
            if "Referer" not in request.headers:
                request.headers["Referer"] = "https://%s/" % csrf._get_host(request)
    elif "session" in request.headers.cookie:
        token = request.headers.cookie["session"].value
        user = User.from_session_token(token)

    request.context["user"] = user or User()
开发者ID:venmo,项目名称:www.gittip.com,代码行数:24,代码来源:authentication.py

示例10: opt_in

 def opt_in(self, desired_username):
     """Given a desired username, return a User object.
     """
     self.set_is_locked(False)
     user = User.from_username(self.participant)
     user.sign_in()
     assert not user.ANON, self.participant  # sanity check
     if self.is_claimed:
         newly_claimed = False
     else:
         newly_claimed = True
         user.participant.set_as_claimed()
         try:
             user.participant.change_username(desired_username)
         except ProblemChangingUsername:
             pass
     return user, newly_claimed
开发者ID:JeffSpies,项目名称:www.gittip.com,代码行数:17,代码来源:__init__.py

示例11: build_wsgi_environ

    def build_wsgi_environ(self, *a, **kw):
        """Extend base class to support authenticating as a certain user.
        """

        # csrf - for both anon and authenticated
        self.cookie[b'csrf_token'] = b'sotokeny'
        kw[b'HTTP_X-CSRF-TOKEN'] = b'sotokeny'

        # user authentication
        auth_as = kw.pop('auth_as', None)
        if auth_as is None:
            if SESSION in self.cookie:
                del self.cookie[SESSION]
        else:
            user = User.from_username(auth_as)
            user.sign_in(self.cookie)

        return Client.build_wsgi_environ(self, *a, **kw)
开发者ID:atunit,项目名称:www.gittip.com,代码行数:18,代码来源:__init__.py

示例12: opt_in

    def opt_in(self, desired_username):
        """Given a desired username, return a User object.
        """
        from gittip.security.user import User

        self.set_is_locked(False)
        user = User.from_username(self.participant.username)
        assert not user.ANON, self.participant  # sanity check
        if self.participant.is_claimed:
            newly_claimed = False
        else:
            newly_claimed = True
            user.participant.set_as_claimed()
            try:
                user.participant.change_username(desired_username)
            except ProblemChangingUsername:
                pass
        if user.participant.is_closed:
            user.participant.update_is_closed(False)
        return user, newly_claimed
开发者ID:LittleFancy,项目名称:www.gittip.com,代码行数:20,代码来源:account_elsewhere.py

示例13: test_suspicious_user_from_username_is_anonymous

 def test_suspicious_user_from_username_is_anonymous(self):
     self.make_participant('alice', is_suspicious=True)
     user = User.from_username('alice')
     assert user.ANON
开发者ID:Aaron1011,项目名称:www.gittip.com,代码行数:4,代码来源:test_user.py

示例14: test_user_can_be_loaded_from_api_key

 def test_user_can_be_loaded_from_api_key(self):
     alice = self.make_participant('alice')
     api_key = alice.recreate_api_key()
     actual = User.from_api_key(api_key).participant.username
     assert actual == 'alice'
开发者ID:Aaron1011,项目名称:www.gittip.com,代码行数:5,代码来源:test_user.py

示例15: test_user_from_bad_id_is_anonymous

 def test_user_from_bad_id_is_anonymous(self):
     user = User.from_username('deadbeef')
     assert user.ANON
开发者ID:Aaron1011,项目名称:www.gittip.com,代码行数:3,代码来源:test_user.py


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