• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.OpenID类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中socialregistration.utils.OpenID的典型用法代码示例。如果您正苦于以下问题:Python OpenID类的具体用法?Python OpenID怎么用?Python OpenID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了OpenID类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: openid_callback

def openid_callback(request, template='socialregistration/openid.html',
	extra_context=dict()):
	"""
	Catches the user when he's redirected back from the provider to our site
	"""
	client = OpenID(
		request,
		'http://%s%s' % (
			Site.objects.get_current().domain,
			reverse('openid_callback')
		),
		request.session.get('openid_provider')
	)
	
	if client.is_valid():
		user = authenticate(identity=request.GET.get('openid.claimed_id'))
		if user is None:
			request.session['socialregistration_user'] = User(username="not_yet")
			request.session['socialregistration_profile'] = OpenIDProfile(
				identity=request.GET.get('openid.claimed_id')
			)
			return HttpResponseRedirect(reverse('socialregistration_setup'))
		else:
			login(request, user)
			return HttpResponseRedirect(_get_next(request))			   
	
	return render_to_response(
		template,
		dict(),
		context_instance=RequestContext(request)
	)
开发者ID:mikeyk,项目名称:django-socialregistration,代码行数:31,代码来源:views.py


示例2: openid_callback

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():
        if request.user.is_authenticated():
            # Handling already logged in users just connecting their accounts
            try:
                profile = OpenIDProfile.objects.get(identity=request.GET.get('openid.claimed_id'))
            except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity
                profile = OpenIDProfile.objects.create(user=request.user,
                    identity=request.GET.get('openid.claimed_id'))

            return HttpResponseRedirect(_get_next(request))

        user = authenticate(identity=request.GET.get('openid.claimed_id'))
        if user is None:
            request.session['socialregistration_user'] = User()
            request.session['socialregistration_profile'] = OpenIDProfile(
                identity=request.GET.get('openid.claimed_id')
            )
            for key, value in getattr(client, 'registration_data', {}).items():
                request.session['social_suggested_%s' % key] = value
            return HttpResponseRedirect(reverse('socialregistration_setup'))
        else:
            login(request, user)
            return HttpResponseRedirect(_get_next(request))

        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:piquadrat,项目名称:django-socialregistration,代码行数:54,代码来源:views.py


示例3: openid_callback

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,代码行数:54,代码来源:views.py


示例4: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session["next"] = _get_next(request)
    request.session["openid_provider"] = request.GET.get("openid_provider")

    client = OpenID(
        request,
        "http%s://%s%s" % (_https(), Site.objects.get_current().domain, reverse("openid_callback")),
        request.GET.get("openid_provider"),
    )
    return client.get_redirect()
开发者ID:statico,项目名称:django-socialregistration,代码行数:13,代码来源:views.py


示例5: openid_callback

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
    """
    if request.GET.get("openid.mode", "") == "cancel":
        return HttpResponseRedirect(_get_next(request))

    client = OpenID(
        request,
        _openid_callback_url(),
        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,
                    site=Site.objects.get_current())
            except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity
                profile = OpenIDProfile.objects.create(user=request.user,
                    identity=identity)

            return successful_account_link(request, profile)

        user = authenticate(identity=identity)
        if user is None:
            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:dasmith2,项目名称:django-socialregistration,代码行数:51,代码来源:views.py


示例6: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session['next'] = _get_next(request)
    request.session['openid_provider'] = request.GET.get('openid_provider')
    
    client = OpenID(
        request,
        'http://%s%s' % (
            Site.objects.get_current().domain,
            reverse('openid_callback')
        ),
        request.GET.get('openid_provider')
    )
    return client.get_redirect()
开发者ID:timjdavey,项目名称:django-socialregistration,代码行数:16,代码来源:views.py


示例7: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session["next"] = _get_next(request)
    request.session["openid_provider"] = request.GET.get("openid_provider")
    client = OpenID(
        request,
        "http%s://%s%s" % (_https(), request.get_host(), reverse("openid_callback")),
        request.GET.get("openid_provider"),
    )
    try:
        return client.get_redirect()
    except DiscoveryFailure:
        request.session["openid_error"] = True
        return HttpResponseRedirect(settings.LOGIN_URL)
开发者ID:oduvan,项目名称:django-socialregistration,代码行数:16,代码来源:views.py


示例8: openid_callback

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():
        if request.user.is_authenticated():
            # Handling already logged in users just connecting their accounts
            try:
                profile, created = OpenIDProfile.objects.get_or_create(user=request.user, identity=request.GET.get('openid.claimed_id'))
            except IntegrityError:
                request.user.message_set.create(message=_('This openid has already been connected to a user.'))
            return HttpResponseRedirect(_get_next(request))
        
        user = authenticate(identity=request.GET.get('openid.claimed_id'))
        if user is None:
            request.session['socialregistration_user'] = User()
            request.session['socialregistration_profile'] = OpenIDProfile(
                identity=request.GET.get('openid.claimed_id')
            )
            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:devioustree,项目名称:django-socialregistration,代码行数:47,代码来源:views.py


示例9: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session['next'] = _get_next(request)
    request.session['openid_provider'] = request.GET.get('openid_provider')

    client = OpenID(
        request,
        _callback_url(request),
        request.GET.get('openid_provider')
    )
    try:
        return client.get_redirect()
    except DiscoveryFailure:
        request.session['openid_error'] = True
        return HttpResponseRedirect(settings.LOGIN_URL)
开发者ID:leopd,项目名称:django-socialregistration,代码行数:17,代码来源:views.py


示例10: openid_callback

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:
            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:jorgebastida,项目名称:django-socialregistration,代码行数:41,代码来源:views.py


示例11: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session['next'] = _get_next(request)
    request.session['openid_provider'] = request.GET.get('openid_provider')

    client = OpenID(
        request,
        'http%s://%s%s' % (
            _https(),
            Site.objects.get_current().domain,
            reverse('openid_callback')
        ),
        request.GET.get('openid_provider')
    )
    try:
        return client.get_redirect()
    except DiscoveryFailure:
        request.session['openid_error'] = True
        return HttpResponseRedirect(settings.LOGIN_URL)
开发者ID:JordanReiter,项目名称:django-socialregistration,代码行数:21,代码来源:views.py


示例12: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session['next'] = _get_next(request)
    request.session['openid_provider'] = request.GET.get('openid_provider')

    provider = request.GET.get('openid_provider')
    client = OpenID(
        request,
        _openid_callback_url(),
        provider
    )
    try:
        return client.get_redirect()
    except DiscoveryFailure:
        return render_to_response(
            'socialregistration/provider_failure.html',
            dict(provider=provider),
            context_instance=RequestContext(request)
        )
开发者ID:dasmith2,项目名称:django-socialregistration,代码行数:21,代码来源:views.py


示例13: openid_redirect

def openid_redirect(request):
    """
    Redirect the user to the openid provider
    """
    request.session['next'] = _get_next(request)
    request.session['openid_provider'] = request.GET.get('openid_provider')
    request.session['socialregistration_connect_object'] = get_object(request.GET)

    client = OpenID(
        request,
        'http%s://%s%s' % (
            _https(),
            Site.objects.get_current().domain,
            reverse('openid_callback')
        ),
        request.GET.get('openid_provider')
    )
    try:
        logger.info("Received redirect to %s from OpenID" % client.get_redirect())
        return client.get_redirect()
    except DiscoveryFailure:
        request.session['openid_error'] = True
        logger.info("OpenID failure, sending user to login.")
        return HttpResponseRedirect(settings.LOGIN_URL)
开发者ID:adamfast,项目名称:django-socialregistration,代码行数:24,代码来源:views.py


示例14: openid_callback

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 'socialregistration_connect_object' in request.session and request.session['socialregistration_connect_object'] != None:
            # this exists so that social credentials can be attached to any arbitrary object using the same callbacks.
            # Under normal circumstances it will not be used. Put an object in request.session named 'socialregistration_connect_object' and it will be used instead.
            # After the connection is made it will redirect to request.session value 'socialregistration_connect_redirect' or settings.LOGIN_REDIRECT_URL or /
            try:
                # get the profile for this facebook UID and type of connected object
                profile = OpenIDProfile.objects.get(identity=identity, content_type=ContentType.objects.get_for_model(request.session['socialregistration_connect_object'].__class__), object_id=request.session['socialregistration_connect_object'].pk)
            except OpenIDProfile.DoesNotExist:
                OpenIDProfile.objects.create(content_object=request.session['socialregistration_connect_object'], identity=identity)

            del request.session['socialregistration_connect_object']
        else:
            if request.user.is_authenticated():
                # Handling already logged in users just connecting their accounts
                try:
                    profile = OpenIDProfile.objects.get(identity=identity, content_type=ContentType.objects.get_for_model(User))
                except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity
                    profile = OpenIDProfile.objects.create(content_object=request.user,
                        identity=identity)

                return HttpResponseRedirect(_get_next(request))

            user = authenticate(identity=identity)
            if user is None:
                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:imrehg,项目名称:django-socialregistration,代码行数:63,代码来源:views.py


示例15: openid_callback

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')
    )
#    print 'hi'
#    print request.GET
    if client.is_valid():
        if request.user.is_authenticated():
            # Handling already logged in users just connecting their accounts
            try:
                profile = OpenIDProfile.all().filter('identity=',request.GET.get('openid.claimed_id')).fetch(1)[0]
            except IndexError: # There can only be one profile with the same identity
                profile = OpenIDProfile(
                    user = request.user,
                    identity=request.GET.get('openid.claimed_id'),
                    real_name=request.GET.get('openid.ax.value.fullname'),
                    username=request.GET.get('openid.ax.value.nickname'),
                    email=request.GET.get('openid.ax.value.email'),
                    pic_url=request.GET.get('openid.ax.value.image'),
                )
                profile.save()

            return HttpResponseRedirect(_get_next(request))

        user = authenticate(identity=request.GET.get('openid.claimed_id'))
        if user is None:
            user = User(username='openid')
            request.session['social_suggested_username'] = request.GET.get('openid.ax.value.nickname')
            request.session['socialregistration_user'] = user
            if request.GET.get('openid.ext2.value.email'):
                request.session['social_suggested_username'] = request.GET.get('openid.ext2.value.email').split('@')[0]
                request.session['socialregistration_profile'] = OpenIDProfile(
                    identity=request.GET.get('openid.claimed_id'),
                    internal_username=request.session['social_suggested_username'],
                    email=request.GET.get('openid.ext2.value.email'),
                    pic_url= "http://www.gravatar.com/avatar/" + md5.md5(request.GET.get('openid.ext2.value.email')).hexdigest() ,
                )
            elif request.GET.get('openid.sreg.email'):
                request.session['social_suggested_username'] = request.GET.get('openid.sreg.nickname')
                request.session['socialregistration_profile'] = OpenIDProfile(
                    identity=request.GET.get('openid.claimed_id'),
                    real_name=request.GET.get('openid.sreg.fullname'),
                    internal_username=request.GET.get('openid.sreg.nickname'),
                    email=request.GET.get('openid.sreg.email'),
                    pic_url="http://www.gravatar.com/avatar/" + md5.md5(request.GET.get('openid.sreg.email')).hexdigest(),
                )
            elif request.GET.get('openid.ext1.value.email'):
                request.session['social_suggested_username'] = request.GET.get('openid.ext1.value.email').split('@')[0]
                request.session['socialregistration_profile'] = OpenIDProfile(
                    identity=request.GET.get('openid.claimed_id'),
                    internal_username=request.session['social_suggested_username'],
                    email=request.GET.get('openid.ext1.value.email'),
                    pic_url= "http://www.gravatar.com/avatar/" + md5.md5(request.GET.get('openid.ext1.value.email')).hexdigest() ,
                )
            else:
                request.session['socialregistration_profile'] = OpenIDProfile(
                    identity=request.GET.get('openid.claimed_id'),
                    real_name=request.GET.get('openid.ax.value.fullname'),
                    internal_username=request.GET.get('openid.ax.value.nickname'),
                    email=request.GET.get('openid.ax.value.email'),
                    pic_url=request.GET.get('openid.ax.value.image'),
                )
            for key, value in getattr(client, 'registration_data', {}).items():
                request.session['social_suggested_%s' % key] = value

            return HttpResponseRedirect(reverse('socialregistration_setup'))
        else:
            login(request, user)
            return HttpResponseRedirect(_get_next(request))

        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:frankk00,项目名称:social-auth-for-django-appengine,代码行数:94,代码来源:views.py


示例16: openid_callback

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')
    )

    try:
        request_args = util.normalDict(request.GET)

        if request.method == 'POST':
            request_args.update(util.normalDict(request.POST))

        if request_args:
            client.complete()
            c = client.consumer

        return_to = util.getViewURL(request, openid_callback)

        response = client.result

        ax_items = {}

        if response.status == consumer.SUCCESS:
            provider = request.session.get('openid_provider')
            # Set the schema uri depending on who the openid provier is:
            # request only name and email by default (same as Google schemas):
            schemas = GoogleOpenIDSchemas()
            if 'yahoo' in provider:
                schemas = YahooOpenIDSchemas()

            if 'myopenid' in provider:
                schemas = MyOpenIDSchemas()

            ax_response = {}
            ax_response = ax.FetchResponse.fromSuccessResponse(response)
            if ax_response:
                # Name and email schemas are always set, but not others so check if they are not empty first:
                birth_date = zip = gender = []
                if schemas.birth_date_schema:
                    birth_date = ax_response.get(schemas.birth_date_schema)
                if schemas.zip_schema:
                    zip =  ax_response.get(schemas.zip_schema)
                if schemas.gender_schema:
                    gender = ax_response.get(schemas.gender_schema)
                ax_items = {
                    'display_name': ax_response.get(schemas.name_schema),
                    'email': ax_response.get(schemas.email_schema),
                    'birth_date': birth_date,
                    'home_zip': zip,
                    'gender': gender,
                }

        request.session['ax_items'] = ax_items

    except Exception, e:
        pass
开发者ID:coxmediagroup,项目名称:django-socialregistration,代码行数:65,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python socket._fileobject函数代码示例发布时间:2022-05-27
下一篇:
Python utils.OAuthClient类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap