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


Python ServiceApi.find_user_credentials_by_actor_id方法代码示例

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


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

示例1: userprofile

# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import find_user_credentials_by_actor_id [as 别名]
def userprofile():
    if not session.has_key('user_id'):
        return redirect('/')
    is_registered = False
    if session.has_key('is_registered'):
        is_registered = session['is_registered']
    user_id = session['user_id']

    if request.is_xhr:
        if request.method == 'GET':
            # determine if this is an update or a new registration
            if is_registered:
                resp_data = ServiceApi.find_user_info(session['actor_id'])
            else:
                # try to extract name from UserCredentials
                creds = ServiceApi.find_user_credentials_by_actor_id(session['actor_id'])
                cntoken = creds['name']
                name = ''
                individual_names_given = ''
                individual_name_family = ''

                try:
                    rcn = re.compile(r'CN=(.*)\sA.+')
                    m = rcn.search(cntoken)
                    if m is not None:
                        name = m.groups()[0]

                        individual_names_given, individual_name_family = name.split(' ', 1)
                except:
                    pass

                resp_data = {'name':name,
                             'contact':{'individual_names_given':individual_names_given,
                                        'individual_name_family':individual_name_family}}

            return jsonify(data=resp_data)
        else:
            form_data = json.loads(request.data)
            if is_registered:
                resp_data = ServiceApi.update_user_info(form_data)

                if isinstance(resp_data, dict) and resp_data.has_key('GatewayError'):
                    return render_json_response(resp_data)
                else:
                    # only thing that can change here for session is name
                    session['name'] = form_data['name']

            else:
                user_id = ServiceApi.create_user_info(session['actor_id'], form_data)

                if isinstance(user_id, dict) and user_id.has_key('GatewayError'):
                    return render_json_response(user_id)
                else:
                    # simulate a signon by setting appropriate session vars
                    session['is_registered'] = True
                    session['user_id']       = user_id
                    session['roles']         = ServiceApi.get_roles_by_actor_id(session['actor_id'])
                    session['name']          = form_data['name']
                    #session['valid_until']  = 0     # @TODO: howto? only in certificate, so logon?

            resp_data = {"success":True}
            return jsonify(data=resp_data)
    else:
        return render_app_template(request.path)
开发者ID:Bobfrat,项目名称:ion-ux,代码行数:66,代码来源:main.py


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