本文整理汇总了Python中service_api.ServiceApi.update_user_info方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceApi.update_user_info方法的具体用法?Python ServiceApi.update_user_info怎么用?Python ServiceApi.update_user_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service_api.ServiceApi
的用法示例。
在下文中一共展示了ServiceApi.update_user_info方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: userprofile
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_user_info [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(user_id)
else:
resp_data = {'contact': {'name': '', 'email': '', 'phone': '', 'address': '', 'city': '', 'postalcode': ''}}
return jsonify(data=resp_data)
else:
form_data = json.loads(request.data)
if is_registered:
ServiceApi.update_user_info(form_data)
else:
ServiceApi.create_user_info(user_id, form_data)
# indicate user is registered
session['is_registered'] = True
resp_data = {"success":True}
return jsonify(data=resp_data)
else:
return render_app_template(request.path)
示例2: userprofile
# 需要导入模块: from service_api import ServiceApi [as 别名]
# 或者: from service_api.ServiceApi import update_user_info [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)