本文整理汇总了Python中service_api.ServiceApi.get_roles_by_actor_id方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceApi.get_roles_by_actor_id方法的具体用法?Python ServiceApi.get_roles_by_actor_id怎么用?Python ServiceApi.get_roles_by_actor_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service_api.ServiceApi
的用法示例。
在下文中一共展示了ServiceApi.get_roles_by_actor_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: session_info
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import get_roles_by_actor_id [as 别名]
def session_info():
# get version info from service gateway
remote_version = ServiceApi.get_version()
ion_ux_version = get_versions()
# ion ux must be first
version = [{ 'lib': 'ux-release', 'version': ion_ux_version }]
# coi services should be second
version.append({'lib':'coi-services-release', 'version': remote_version.pop('coi-services-release', 'unknown')})
# sort the rest by alpha
for k,v in sorted(remote_version.iteritems()):
version.append({'lib':k, 'version': v})
# trim off "-release" and "-dev"
for ver in version:
ver['lib'] = ver['lib'].replace("-release", "")
ver['version'] = ver['version'].replace("-dev", "")
session_values = {'user_id': None, 'roles': None, 'is_registered': False, 'is_logged_in': False, 'ui_mode': UI_MODE, 'version': version }
if session.has_key('user_id'):
roles = ServiceApi.get_roles_by_actor_id(session['actor_id'])
session_values.update({'name': session['name'],
'user_id': session['user_id'],
'actor_id': session['actor_id'],
'roles': roles,
'is_registered': session['is_registered'],
'is_logged_in': True,
'ui_theme_dark': session['ui_theme_dark']})
return jsonify(data=session_values)
示例2: userprofile
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import get_roles_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)