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


Python User.by_name方法代码示例

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


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

示例1: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
    def authenticate(self, environ, identity):
        if not ('login' in identity and 'password' in identity):
            return None

        login = identity['login']
        user = User.by_name(login)

        ## HDX HACK ##
        if user is None:
            users = User.by_email(login)
            try:
                user = users[0]
            except:
                user = None
        ## END HDX HACK ##

        if user is None:
            log.debug('Login failed - username %r not found', login)
        elif not user.is_active():
            log.debug('Login as %r failed - user isn\'t active', login)
        elif not user.validate_password(identity['password']):
            log.debug('Login as %r failed - password not valid', login)
        else:
            return user.name

        return None
开发者ID:aalecs,项目名称:hdx-ckan-ci,代码行数:28,代码来源:authenticator.py

示例2: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
    def authenticate(self, environ, identity):
        '''
        Authenticate and extract identity from OAuth2 tokens
        '''
        request = Request(environ)
        log.debug('Repoze OAuth authenticate')
        if 'oauth2.token' in identity:
            oauth = OAuth2Session(
                self.client_id,
                token=identity['oauth2.token'])
            profile_response = oauth.get(self.profile_api_url)
            profile_data = profile_response.json()
            if not profile_data['authenticated']:
                return None

            user_data = profile_data['principal']

            user = User.by_name(user_data['username'])

            if user is None:
                user = User()
                user.name = user_data['username']
                user.email = user_data['email']
                user.fullname = u"{} {}".format(
                    user_data['name'], user_data['surname'])
                user.save()
                user.activate()
                user.save()

            identity.update({'repoze.who.userid': user.name})
            self._redirect_from_callback(request, identity)
            return user.name

        return None
开发者ID:pwr-inf,项目名称:ckanext-oauth2,代码行数:36,代码来源:repozewho.py

示例3: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
 def authenticate(self, environ, identity):
     if not 'login' in identity or not 'password' in identity:
         return None
     user = User.by_name(identity.get('login'))
     if user is None: 
         return None
     if user.validate_password(identity.get('password')):
         return user.name
     return None
开发者ID:AdamJensen-dk,项目名称:ckan-drupal,代码行数:11,代码来源:authenticator.py

示例4: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
 def authenticate(self, environ, identity):
     '''Fetch the user given its username in identity'''
     if 'username' in identity:
         user = User.by_name(identity['username'])
         if user is None:
             return None
         else:
             identity.update({'repoze.who.userid': user.name})
             return user.name
     return None
开发者ID:etalab,项目名称:ckanext-youckan,代码行数:12,代码来源:repozewho.py

示例5: test_authenticate_step_two

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
 def test_authenticate_step_two(self):
     plugin = self._makeOne()
     environ = {"REQUEST_METHOD": "GET", "QUERY_STRING": "oauth_token=foo", "ckan.who.oauth.challenge": "1"}
     identity = plugin.identify(environ)
     username = identity.get("repoze.who.userid")
     self.assertEqual(username, "boz")
     user = User.by_name("boz")
     self.assertEqual(user.email, "[email protected]")
     groups = Session.query(AuthorizationGroup).filter(AuthorizationGroup.users.contains(user))
     self.assertEqual(groups.count(), 1)
开发者ID:okfn,项目名称:ckanext-oauth,代码行数:12,代码来源:test_general.py

示例6: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
 def authenticate(self, environ, identity):
     if not 'login' in identity or not 'password' in identity:
         return None
     user = User.by_name(identity.get('login'))
     if user is None:
         log.debug('Login failed - username %r not found', identity.get('login'))
         return None
     if user.validate_password(identity.get('password')):
         return user.name
     log.debug('Login as %r failed - password not valid', identity.get('login'))
     return None
开发者ID:31H0B1eV,项目名称:ckan,代码行数:13,代码来源:authenticator.py

示例7: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
 def authenticate(self, environ, identity):
     if 'repoze.who.plugins.openid.userid' in identity:
         openid = identity.get('repoze.who.plugins.openid.userid')
         user = User.by_openid(openid)
         if user is None:
             # TODO: Implement a mask to ask for an alternative user 
             # name instead of just using the OpenID identifier. 
             name = identity.get('repoze.who.plugins.openid.nickname')
             if not User.check_name_available(name):
                 name = openid
             if User.by_name(name):
                 name = openid
             user = User(openid=openid, name=name,
                     fullname=identity.get('repoze.who.plugins.openid.fullname'),
                     email=identity.get('repoze.who.plugins.openid.email'))
             Session.add(user)
             Session.commit()
             Session.remove()
         return user.name
     return None
开发者ID:okfn,项目名称:ckan-old,代码行数:22,代码来源:authenticator.py

示例8: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import by_name [as 别名]
    def authenticate(self, environ, identity):
        if not 'login' in identity or not 'password' in identity:
            return None
        user = User.by_name(identity.get('login'))
        if user is None:
            log.debug('Login failed - username %r not found', identity.get('login'))
            return None

        qgovUser = Session.query(QGOVUser).filter_by(name = identity.get('login')).first()
        if qgovUser.login_attempts >= 10:
            log.debug('Login as %r failed - account is locked', identity.get('login'))
        elif user.validate_password(identity.get('password')):
            # reset attempt count to 0
            qgovUser.login_attempts = 0
            Session.commit()
            return user.name
        else:
            log.debug('Login as %r failed - password not valid', identity.get('login'))

        qgovUser.login_attempts += 1
        Session.commit()
        return None
开发者ID:qld-gov-au,项目名称:ckanext-qgov-data,代码行数:24,代码来源:authenticator.py


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