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


Python UserApi.authenticate方法代码示例

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


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

示例1: test_unit__authenticate_user___err__wrong_user

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
 def test_unit__authenticate_user___err__wrong_user(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(AuthenticationFailed):
         api.authenticate('[email protected]', 'wrong_password')
开发者ID:tracim,项目名称:tracim,代码行数:10,代码来源:test_user_api.py

示例2: test_unit__authenticate_user___ok__new_user_ldap_auth_custom_profile

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
    def test_unit__authenticate_user___ok__new_user_ldap_auth_custom_profile(self):
        # TODO - G.M - 2018-12-05 - [ldap_profile]
        # support for profile attribute disabled
        # Should be reenabled later probably with a better code
        class fake_ldap_connector(object):

            def authenticate(self, email: str, password: str):
                if not email == '[email protected]' \
                        and password == 'professor':
                    return None
                return [None, {'mail': ['[email protected]'],
                               'givenName': ['Hubert'],
                               'profile': ['trusted-users'],
                               }]
        api = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        user = api.authenticate('[email protected]', 'professor', fake_ldap_connector())  # nopep8
        assert isinstance(user, User)
        assert user.email == '[email protected]'
        assert user.auth_type == AuthType.LDAP
        assert user.display_name == 'Hubert'
        assert user.profile.name == 'trusted-users'
开发者ID:tracim,项目名称:tracim,代码行数:27,代码来源:test_user_api.py

示例3: _authenticate_user

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
 def _authenticate_user(
     self,
     request: Request,
     email: typing.Optional[str],
     password: typing.Optional[str],
 ) -> typing.Optional[User]:
     """
     Helper to authenticate user in pyramid request
     from user email and password
     :param request: pyramid request
     :return: User or None
     """
     app_config = request.registry.settings['CFG']
     uapi = UserApi(None, session=request.dbsession, config=app_config)
     ldap_connector = None
     if AuthType.LDAP in app_config.AUTH_TYPES:
         ldap_connector = get_ldap_connector(request)
     try:
         user = uapi.authenticate(
             email=email,
             password=password,
             ldap_connector=ldap_connector
         )
         return user
     except AuthenticationFailed:
         return None
开发者ID:tracim,项目名称:tracim,代码行数:28,代码来源:authentification.py

示例4: test_unit__authenticate_user___err__no_ldap_connector

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
 def test_unit__authenticate_user___err__no_ldap_connector(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(MissingLDAPConnector):
         user = api.authenticate('[email protected]', 'professor')
开发者ID:tracim,项目名称:tracim,代码行数:10,代码来源:test_user_api.py

示例5: authDomainUser

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
 def authDomainUser(self, realmname: str, username: str, password: str, environ: typing.Dict[str, typing.Any]) -> bool:
     """
     If you ever feel the need to send a request al-mano with a curl, this is the function that'll be called by
     http_authenticator to validate the password sent
     """
     session = environ['tracim_context'].dbsession
     api = UserApi(None, session, self.app_config)
     try:
         api.authenticate(
             email=username,
             password=password,
             ldap_connector=environ['tracim_registry'].ldap_connector
         )
         transaction.commit()
     except AuthenticationFailed:
         return False
     return True
开发者ID:tracim,项目名称:tracim,代码行数:19,代码来源:authentification.py

示例6: test_unit__authenticate_user___ok__nominal_case

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
 def test_unit__authenticate_user___ok__nominal_case(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     user = api.authenticate('[email protected]', '[email protected]')
     assert isinstance(user, User)
     assert user.email == '[email protected]'
     assert user.auth_type == AuthType.INTERNAL
开发者ID:tracim,项目名称:tracim,代码行数:12,代码来源:test_user_api.py

示例7: test_unit__authenticate_user___err__user_not_active

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
 def test_unit__authenticate_user___err__user_not_active(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     gapi = GroupApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     groups = [gapi.get_one_with_name('users')]
     user = api.create_user(
         email='[email protected]',
         password='password',
         name='bob',
         groups=groups,
         timezone='Europe/Paris',
         do_save=True,
         do_notify=False,
     )
     api.disable(user)
     with pytest.raises(AuthenticationFailed):
         api.authenticate('[email protected]', '[email protected]')
开发者ID:tracim,项目名称:tracim,代码行数:26,代码来源:test_user_api.py

示例8: login

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
    def login(self, context, request: TracimRequest, hapic_data=None):
        """
        Logs the user into the system.
        In case of success, the JSON returned is the user profile.
        In that case, a cookie is created with a session_key and an expiration date.
        Eg. : `session_key=932d2ad68f3a094c2d4da563ccb921e6479729f5b5f707eba91d4194979df20831be48a0; expires=Mon, 22-Oct-2018 19:37:02 GMT; Path=/; SameSite=Lax`
        """

        login = hapic_data.body
        app_config = request.registry.settings['CFG']  # type: CFG
        uapi = UserApi(
            None,
            session=request.dbsession,
            config=app_config,
        )
        ldap_connector = None
        if AuthType.LDAP in app_config.AUTH_TYPES:
            ldap_connector = get_ldap_connector(request)
        user = uapi.authenticate(login.email, login.password, ldap_connector)
        remember(request, user.user_id)
        return uapi.get_user_with_context(user)
开发者ID:tracim,项目名称:tracim,代码行数:23,代码来源:session_controller.py

示例9: test_unit__authenticate_user___ok__new_user_ldap_auth

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import authenticate [as 别名]
    def test_unit__authenticate_user___ok__new_user_ldap_auth(self):
        class fake_ldap_connector(object):

            def authenticate(self, email: str, password: str):
                if not email == '[email protected]' \
                        and password == 'professor':
                    return None
                return [None, {'mail': ['[email protected]'],
                               'givenName': ['Hubert'],
                               }]
        api = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        user = api.authenticate('[email protected]', 'professor', fake_ldap_connector())  # nopep8
        assert isinstance(user, User)
        assert user.email == '[email protected]'
        assert user.auth_type == AuthType.LDAP
        assert user.display_name == 'Hubert'
        assert user.profile.name == 'users'
开发者ID:tracim,项目名称:tracim,代码行数:23,代码来源:test_user_api.py


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