本文整理汇总了Python中socialregistration.utils.OpenID.get_user_info方法的典型用法代码示例。如果您正苦于以下问题:Python OpenID.get_user_info方法的具体用法?Python OpenID.get_user_info怎么用?Python OpenID.get_user_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socialregistration.utils.OpenID
的用法示例。
在下文中一共展示了OpenID.get_user_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: openid_callback
# 需要导入模块: from socialregistration.utils import OpenID [as 别名]
# 或者: from socialregistration.utils.OpenID import get_user_info [as 别名]
def openid_callback(request, template='socialregistration/openid.html',
extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'):
"""
Catches the user when he's redirected back from the provider to our site
"""
client = OpenID(
request,
'http%s://%s%s' % (
_https(),
Site.objects.get_current().domain,
reverse('openid_callback')
),
request.session.get('openid_provider')
)
if client.is_valid():
identity = client.result.identity_url
if request.user.is_authenticated():
# Handling already logged in users just connecting their accounts
try:
profile = OpenIDProfile.objects.get(identity=identity)
except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity
profile = OpenIDProfile.objects.create(user=request.user,
identity=identity)
return HttpResponseRedirect(_get_next(request))
user = authenticate(identity=identity)
if user is None:
user = User()
user_info = client.get_user_info()
user.first_name, user.last_name = user_info.get('fullname', ' ').split(' ', 1)
user.email = user_info.get('email', '')
request.session['socialregistration_user'] = user
request.session['socialregistration_profile'] = OpenIDProfile(
identity=identity
)
return HttpResponseRedirect(reverse('socialregistration_setup'))
if not user.is_active:
return render_to_response(
account_inactive_template,
extra_context,
context_instance=RequestContext(request)
)
login(request, user)
return HttpResponseRedirect(_get_next(request))
return render_to_response(
template,
dict(),
context_instance=RequestContext(request)
)