本文整理汇总了Python中past.model.user.UserAlias.create_new_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserAlias.create_new_user方法的具体用法?Python UserAlias.create_new_user怎么用?Python UserAlias.create_new_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类past.model.user.UserAlias
的用法示例。
在下文中一共展示了UserAlias.create_new_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _save_user_and_token
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import create_new_user [as 别名]
def _save_user_and_token(token_dict, user_info, openid_type):
ua = UserAlias.get(openid_type, user_info.get_user_id())
if not ua:
if not g.user:
ua = UserAlias.create_new_user(openid_type,
user_info.get_user_id(), user_info.get_nickname())
else:
ua = UserAlias.bind_to_exists_user(g.user,
openid_type, user_info.get_user_id())
if not ua:
return None
##设置个人资料(头像等等)
u = User.get(ua.user_id)
u.set_avatar_url(user_info.get_avatar())
u.set_icon_url(user_info.get_icon())
##保存access token
if openid_type == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
OAuth2Token.add(ua.id, token_dict.get("access_token"),
token_dict.get("access_token_secret", ""))
else:
OAuth2Token.add(ua.id, token_dict.get("access_token"),
token_dict.get("refresh_token", ""))
##set cookie,保持登录状态
if not g.user:
g.user = User.get(ua.user_id)
set_user_cookie(g.user, session)
return g.user
示例2: _save_user_and_token
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import create_new_user [as 别名]
def _save_user_and_token(token_dict, thirdparty_user, openid_type):
first_connect = False
ua = UserAlias.get(openid_type, thirdparty_user.get_user_id())
if not ua:
if not g.user:
ua = UserAlias.create_new_user(openid_type,
thirdparty_user.get_user_id(), thirdparty_user.get_nickname())
else:
ua = UserAlias.bind_to_exists_user(g.user,
openid_type, thirdparty_user.get_user_id())
first_connect = True
if not ua:
return None
##设置个人资料(头像等等)
u = User.get(ua.user_id)
u.set_avatar_url(thirdparty_user.get_avatar())
u.set_icon_url(thirdparty_user.get_icon())
##把各个第三方的uid保存到profile里面
k = openid_type
v = {
"uid": thirdparty_user.get_uid(),
"name": thirdparty_user.get_nickname(),
"intro": thirdparty_user.get_intro(),
"signature": thirdparty_user.get_signature(),
"avatar": thirdparty_user.get_avatar(),
"icon": thirdparty_user.get_icon(),
"email": thirdparty_user.get_email(),
"first_connect": "Y" if first_connect else "N",
}
u.set_profile_item(k, json_encode(v))
##保存access token
if openid_type == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
OAuth2Token.add(ua.id, token_dict.get("access_token"),
token_dict.get("access_token_secret", ""))
else:
OAuth2Token.add(ua.id, token_dict.get("access_token"),
token_dict.get("refresh_token", ""))
##set cookie,保持登录状态
if not g.user:
g.user = User.get(ua.user_id)
set_user_cookie(g.user, session)
return g.user