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


Python User.fullname方法代码示例

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


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

示例1: authenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import fullname [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

示例2: preauthenticate

# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import fullname [as 别名]
    def preauthenticate(self, environ, identity):
        # turn the oauth identity into a CKAN one; set it in our identity
        import oauth2 as oauth
        try:
            access_token = dict(urlparse.parse_qsl(identity['userdata']))
            oauth_token = access_token['oauth_token']
            oauth_token_secret = access_token['oauth_token_secret']
        except KeyError:
            return None
        access_token = oauth.Token(oauth_token,
                                   oauth_token_secret)
        client = oauth.Client(self.consumer, access_token)
        resp, content = client.request(self.user_url, "GET")
        data = json.loads(content)
        user_id = data['id']
        logging.info("Preauth: Got oauth user data for user %s" % user_id)
        user = User.by_openid(user_id)
        if user is None:
            user = User(openid=user_id,
                        name=data['id'],
                        fullname=data['name'],
                        email=data['mail'])
            Session.add(user)
        else:
            user.fullname = data['name'] # if the name is updated
        Session.commit()
        Session.remove()
        logging.info("Preauth: Created new/updated user %s" % user_id)

        # deal with groups
        user_groups = data['groups']
        _sync_auth_groups(user, user_groups)
        name = user.name.encode("utf8")
        logging.info("Preauth: Returning user identifier %s" % name)
        identity['repoze.who.userid'] = name 
        return identity
开发者ID:okfn,项目名称:ckanext-oauth,代码行数:38,代码来源:plugin.py


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