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


Python User.from_username方法代码示例

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


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

示例1: test_user_can_be_loaded_from_session_token

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_user_can_be_loaded_from_session_token(self):
     self.make_participant('alice')
     user = User.from_username('alice')
     user.sign_in(SimpleCookie())
     token = user.participant.session_token
     actual = User.from_session_token(token).participant.username
     assert actual == 'alice'
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:9,代码来源:test_user.py

示例2: test_user_from_expired_session_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 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:SirCmpwn,项目名称:gratipay.com,代码行数:10,代码来源:test_user.py

示例3: test_session_cookie_is_secure_if_it_should_be

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_session_cookie_is_secure_if_it_should_be(self):
     canonical_scheme = gratipay.canonical_scheme
     gratipay.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:
         gratipay.canonical_scheme = canonical_scheme
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:13,代码来源:test_user.py

示例4: test_session_is_regularly_refreshed

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 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:SirCmpwn,项目名称:gratipay.com,代码行数:14,代码来源:test_user.py

示例5: opt_in

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def opt_in(self, desired_username):
     """Given a desired username, return a User object.
     """
     from gratipay.security.user import User
     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:mccolgst,项目名称:www.gittip.com,代码行数:20,代码来源:account_elsewhere.py

示例6: build_wsgi_environ

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
    def build_wsgi_environ(self, *a, **kw):
        """Extend base class to support authenticating as a certain user.
        """

        # csrf - for both anon and authenticated
        csrf_token = kw.get('csrf_token', b'sotokeny')
        if csrf_token:
            self.cookie[b'csrf_token'] = csrf_token
            kw[b'HTTP_X-CSRF-TOKEN'] = csrf_token

        # 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:beerm,项目名称:gratipay.com,代码行数:22,代码来源:__init__.py

示例7: build_wsgi_environ

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
    def build_wsgi_environ(self, *a, **kw):
        """Extend base class to support authenticating as a certain user.
        """

        self.cookie.clear()

        # csrf - for both anon and authenticated
        csrf_token = kw.get('csrf_token', b'ThisIsATokenThatIsThirtyTwoBytes')
        if csrf_token:
            self.cookie[b'csrf_token'] = csrf_token
            kw[b'HTTP_X-CSRF-TOKEN'] = csrf_token

        # user authentication
        auth_as = kw.pop('auth_as', None)
        if auth_as:
            user = User.from_username(auth_as)
            user.sign_in(self.cookie)

        for k, v in kw.pop('cookies', {}).items():
            self.cookie[k] = v

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

示例8: test_suspicious_user_from_username_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 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:9cat,项目名称:templecoin-gratipay,代码行数:6,代码来源:test_user.py

示例9: test_show_plural_no_members_as_team_to_admin

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_show_plural_no_members_as_team_to_admin(self):
     group = self.make_participant('Group', number='plural')
     self.make_participant('Admin', is_admin=True)
     assert group.show_as_team(User.from_username('Admin'))
开发者ID:9cat,项目名称:templecoin-gratipay,代码行数:6,代码来源:test_teams.py

示例10: test_show_plural_no_members_as_team_to_self

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_show_plural_no_members_as_team_to_self(self):
     group = self.make_participant('Group', number='plural')
     assert group.show_as_team(User.from_username('Group'))
开发者ID:9cat,项目名称:templecoin-gratipay,代码行数:5,代码来源:test_teams.py

示例11: test_dont_show_plural_no_members_as_team_to_auth

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_dont_show_plural_no_members_as_team_to_auth(self):
     group = self.make_participant('Group', number='plural')
     self.make_participant('alice')
     assert not group.show_as_team(User.from_username('alice'))
开发者ID:9cat,项目名称:templecoin-gratipay,代码行数:6,代码来源:test_teams.py

示例12: test_show_as_team_to_non_team_member

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_show_as_team_to_non_team_member(self):
     self.make_participant('alice')
     self.team.add_member(self.make_participant('bob', claimed_time='now'))
     user = User.from_username('alice')
     assert self.team.show_as_team(user)
开发者ID:9cat,项目名称:templecoin-gratipay,代码行数:7,代码来源:test_teams.py

示例13: test_show_as_team_to_admin

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_show_as_team_to_admin(self):
     self.make_participant('alice', is_admin=True)
     user = User.from_username('alice')
     assert self.team.show_as_team(user)
开发者ID:9cat,项目名称:templecoin-gratipay,代码行数:6,代码来源:test_teams.py

示例14: test_user_from_bad_username_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_user_from_bad_username_is_anonymous(self):
     user = User.from_username('deadbeef')
     assert user.ANON
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:5,代码来源:test_user.py

示例15: test_signed_out_user_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_username [as 别名]
 def test_signed_out_user_is_anonymous(self):
     self.make_participant('alice')
     alice = User.from_username('alice')
     assert not alice.ANON
     alice.sign_out(SimpleCookie())
     assert alice.ANON
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:8,代码来源:test_user.py


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