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


Python OpenID.get_user_info方法代码示例

本文整理汇总了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)
    )
开发者ID:diegomosela,项目名称:django-socialregistration,代码行数:56,代码来源:views.py


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