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

Python utils.load_backends函数代码示例

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

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



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

示例1: setUp

 def setUp(self):
     HTTPretty.enable()
     self.backend = module_member(self.backend_path)
     self.complete_url = "/complete/{0}/".format(self.backend.name)
     self.strategy = TestStrategy(self.backend, TestStorage, redirect_uri=self.complete_url)
     self.strategy.set_settings(
         {"SOCIAL_AUTH_AUTHENTICATION_BACKENDS": (self.backend_path, "tests.backends.broken_test.BrokenBackendAuth")}
     )
     # Force backends loading to trash PSA cache
     load_backends(self.strategy.get_setting("SOCIAL_AUTH_AUTHENTICATION_BACKENDS"), force_load=True)
开发者ID:bobhsr,项目名称:python-social-auth,代码行数:10,代码来源:open_id.py


示例2: test_load_backends

    def test_load_backends(self):
        loaded_backends = load_backends((
            'social.backends.github.GithubOAuth2',
            'social.backends.facebook.FacebookOAuth2',
            'social.backends.flickr.FlickrOAuth'
        ), force_load=True)
        keys = list(loaded_backends.keys())
        keys.sort()
        self.assertEqual(keys, ['facebook', 'flickr', 'github'])

        backends = ()
        loaded_backends = load_backends(backends, force_load=True)
        self.assertEqual(len(list(loaded_backends.keys())), 0)
开发者ID:2070616d,项目名称:TP3,代码行数:13,代码来源:test_utils.py


示例3: test_load_backends

    def test_load_backends(self):
        loaded_backends = load_backends((
            'social.backends.github.GithubOAuth2',
            'social.backends.facebook.FacebookOAuth2',
            'social.backends.flickr.FlickrOAuth'
        ))
        keys = list(loaded_backends.keys())
        keys.sort()
        expect(keys).to.equal(['facebook', 'flickr', 'github'])

        backends = ()
        loaded_backends = load_backends(backends, force_load=True)
        expect(len(list(loaded_backends.keys()))).to.equal(0)
开发者ID:CodersClan,项目名称:python-social-auth,代码行数:13,代码来源:utils_tests.py


示例4: register

def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, "email")
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    return render(
        request,
        "accounts/register.html",
        {
            "registration_email": "email" in backends,
            "registration_backends": backends - set(["email"]),
            "title": _("User registration"),
            "form": form,
        },
    )
开发者ID:electrolinux,项目名称:weblate,代码行数:28,代码来源:views.py


示例5: register

def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, 'email')
    else:
        form = form_class()

    backends = set(load_backends(BACKENDS).keys())

    return render(
        request,
        'accounts/register.html',
        {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        }
    )
开发者ID:blockgiven,项目名称:weblate,代码行数:28,代码来源:views.py


示例6: view_profile

def view_profile(request, user_id, **kwargs):
	query_set = User.objects.filter(id=user_id)
	if not query_set.exists():
		return view_profile(request, request.user.id, error_messages=['User with user_id='+str(user_id)+' could not be found.'])
	user = query_set[0]

	profile = None
	query_set = UserProfile.objects.filter(user=user)
	if not query_set.exists():
		profile = UserProfile()
		profile.user = user
		profile.save()
	else:
		profile = query_set[0]

	context_dict = {}

	if int(user_id) == int(request.user.id):
		context_dict = {
			'user_form': EditUserForm(initial=model_to_dict(user)),
			'profile_form': UserProfileForm(initial=model_to_dict(profile)),
			'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS),
			'editing': 'editing' in kwargs and kwargs['editing'] == 'editing',
		}
	context_dict['disp_user'] = user
	context_dict['disp_user_is_sm'] = (user.is_superuser) or (Permission.objects.get(codename='site_manager') in user.user_permissions.all()) #user.has_perm('users.site_manager')

	if 'error_messages' in kwargs:
		context_dict['error_messages'] = kwargs['error_messages']

	return render(request, 'profile.html', context_dict)
开发者ID:mas2tg,项目名称:cs3240-f16-team07,代码行数:31,代码来源:views.py


示例7: weblate_login

def weblate_login(request):
    '''
    Login handler, just wrapper around login.
    '''

    # Redirect logged in users to profile
    if request.user.is_authenticated():
        return redirect('profile')

    # Redirect if there is only one backend
    auth_backends = list(load_backends(BACKENDS).keys())
    if len(auth_backends) == 1 and auth_backends[0] != 'email':
        return redirect('social:begin', auth_backends[0])

    return auth_views.login(
        request,
        template_name='accounts/login.html',
        authentication_form=LoginForm,
        extra_context={
            'login_backends': [
                x for x in auth_backends if x != 'email'
            ],
            'can_reset': 'email' in auth_backends,
            'title': _('Login'),
        }
    )
开发者ID:Intrainos,项目名称:weblate,代码行数:26,代码来源:views.py


示例8: index

def index(request, template_name='index.html'):

    user = request.user
    print "User : ", user

    access_token = None
    if user.is_authenticated():

        # get the last login provider
        provider = request.session['social_auth_last_login_backend']
        print "provider : ", provider
        social = user.social_auth.get(provider=provider)
        print "social.extra_data : ", social.extra_data
        access_token = social.extra_data['access_token']
        print "access_token", access_token

        # print "social_auth : ", user.social_auth
        # print "social_auth.values_list('provider') : ", user.social_auth.values_list('provider')
        # print "social_auth.values_list('extra_data') : ", user.social_auth.values_list('extra_data')
        # print "social_auth.provider : ", user.social_auth.provider
        # social = user.social_auth.get(provider='google')
        # print "social : ", social
        # print "social.extra_data['access_token'] : ", social.extra_data['access_token']

    context = {
        'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS),
        'access_token': access_token,
    }

    return render(request, template_name, context)
开发者ID:vfdev-5,项目名称:TestRestApi2,代码行数:30,代码来源:views.py


示例9: register

def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, "email")
    else:
        form = form_class()

    backends = load_backends(BACKENDS).keys()

    # Redirect if there is only one backend
    if len(backends) == 1 and backends[0] != "email":
        return redirect("social:begin", backends[0])

    backends = set(backends)

    return render(
        request,
        "accounts/register.html",
        {
            "registration_email": "email" in backends,
            "registration_backends": backends - set(["email"]),
            "title": _("User registration"),
            "form": form,
        },
    )
开发者ID:josben77,项目名称:weblate,代码行数:34,代码来源:views.py


示例10: register

def register(request):
    """
    Registration form.
    """
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, "email")
    else:
        form = form_class()

    return render_to_response(
        "accounts/register.html",
        RequestContext(
            request,
            {
                "registration_backends": [x for x in load_backends(BACKENDS).keys() if x != "email"],
                "title": _("User registration"),
                "form": form,
            },
        ),
    )
开发者ID:spc-12,项目名称:weblate,代码行数:27,代码来源:views.py


示例11: reset_password

def reset_password(request):
    '''
    Password reset handling.
    '''
    if 'email' not in load_backends(BACKENDS).keys():
        messages.error(
            request,
            _('Can not reset password, email authentication is disabled!')
        )
        return redirect('login')

    if request.method == 'POST':
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['email']
            user.set_unusable_password()
            user.save()
            if not request.session.session_key:
                request.session.create()
            request.session['password_reset'] = True
            return complete(request, 'email')
    else:
        form = ResetForm()

    return render(
        request,
        'accounts/reset.html',
        {
            'title': _('Password reset'),
            'form': form,
        }
    )
开发者ID:Intrainos,项目名称:weblate,代码行数:32,代码来源:views.py


示例12: setUp

 def setUp(self):
     HTTPretty.enable()
     self.backend = module_member(self.backend_path)
     self.strategy = TestStrategy(self.backend, TestStorage)
     self.name = self.backend.name.upper().replace("-", "_")
     self.complete_url = self.strategy.build_absolute_uri(self.raw_complete_url.format(self.backend.name))
     backends = (self.backend_path, "social.tests.backends.test_broken.BrokenBackendAuth")
     self.strategy.set_settings({"SOCIAL_AUTH_AUTHENTICATION_BACKENDS": backends})
     self.strategy.set_settings(self.extra_settings())
     # Force backends loading to trash PSA cache
     load_backends(backends, force_load=True)
     User.reset_cache()
     TestUserSocialAuth.reset_cache()
     TestNonce.reset_cache()
     TestAssociation.reset_cache()
     TestCode.reset_cache()
开发者ID:relsi,项目名称:w2p-social-auth,代码行数:16,代码来源:base.py


示例13: user_profile

def user_profile(request):

    profile = request.user.get_profile()

    if request.method == "POST":
        # Read params
        form = ProfileForm(request.POST, instance=profile)
        subscriptionform = SubscriptionForm(request.POST, instance=profile)
        userform = UserForm(request.POST, instance=request.user)
        if appsettings.DEMO_SERVER and request.user.username == "demo":
            messages.warning(request, _("You can not change demo profile on the demo server."))
            return redirect("profile")

        if form.is_valid() and userform.is_valid() and subscriptionform.is_valid():
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = redirect("profile")

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _("Your profile has been updated."))

            return response
    else:
        form = ProfileForm(instance=profile)
        subscriptionform = SubscriptionForm(instance=profile)
        userform = UserForm(instance=request.user)

    social = request.user.social_auth.all()
    social_names = [assoc.provider for assoc in social]
    new_backends = [x for x in load_backends(BACKENDS).keys() if x == "email" or x not in social_names]

    response = render_to_response(
        "accounts/profile.html",
        RequestContext(
            request,
            {
                "form": form,
                "userform": userform,
                "subscriptionform": subscriptionform,
                "profile": profile,
                "title": _("User profile"),
                "licenses": Project.objects.exclude(license=""),
                "associated": social,
                "new_backends": new_backends,
            },
        ),
    )
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language)
    return response
开发者ID:spc-12,项目名称:weblate,代码行数:60,代码来源:views.py


示例14: context

def context(**extra):
    """
    Adding default context to rendered page.
    """
    return dict({
        'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS),
    }, **extra)
开发者ID:VladimirFilonov,项目名称:socraticqs2,代码行数:7,代码来源:views.py


示例15: reset_password

def reset_password(request):
    """
    Password reset handling.
    """
    if "email" not in load_backends(BACKENDS).keys():
        messages.error(request, _("Can not reset password, email authentication is disabled!"))
        return redirect("login")

    if request.method == "POST":
        form = ResetForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data["email"]
            user.set_unusable_password()
            user.save()

            # Force creating new session
            request.session.create()
            if request.user.is_authenticated():
                logout(request)

            request.session["password_reset"] = True
            return complete(request, "email")
    else:
        form = ResetForm()

    return render(request, "accounts/reset.html", {"title": _("Password reset"), "form": form})
开发者ID:dtschan,项目名称:weblate,代码行数:26,代码来源:views.py


示例16: register

def register(request):
    '''
    Registration form.
    '''
    if appsettings.REGISTRATION_CAPTCHA:
        form_class = CaptchaRegistrationForm
    else:
        form_class = RegistrationForm

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and appsettings.REGISTRATION_OPEN:
            return complete(request, 'email')
    else:
        form = form_class()

    backends = load_backends(BACKENDS).keys()

    # Redirect if there is only one backend
    if len(backends) == 1 and backends[0] != 'email':
        return redirect('social:begin', backends[0])

    backends = set(backends)

    return render(
        request,
        'accounts/register.html',
        {
            'registration_email': 'email' in backends,
            'registration_backends': backends - set(['email']),
            'title': _('User registration'),
            'form': form,
        }
    )
开发者ID:ejjoman,项目名称:weblate,代码行数:34,代码来源:views.py


示例17: setUp

 def setUp(self):
     HTTPretty.enable()
     Backend = module_member(self.backend_path)
     self.strategy = TestStrategy(TestStorage)
     self.complete_url = self.raw_complete_url.format(Backend.name)
     self.backend = Backend(self.strategy, redirect_uri=self.complete_url)
     self.strategy.set_settings({
         'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': (
             self.backend_path,
             'social.tests.backends.test_broken.BrokenBackendAuth'
         )
     })
     # Force backends loading to trash PSA cache
     load_backends(
         self.strategy.get_setting('SOCIAL_AUTH_AUTHENTICATION_BACKENDS'),
         force_load=True
     )
开发者ID:PublicInMotionGmbH,项目名称:python-social-auth,代码行数:17,代码来源:open_id.py


示例18: signin

def signin(req):
    from astrometry.net import settings
    from social.backends.utils import load_backends
    ctxt = RequestContext(req)
    ctxt.update({
            'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS)
            })
    return render_to_response('signin.html', ctxt)
开发者ID:Carl4,项目名称:astrometry.net,代码行数:8,代码来源:home.py


示例19: context

def context(**extra):
    return dict(
        {
            "plus_id": getattr(settings, "SOCIAL_AUTH_GOOGLE_PLUS_KEY", None),
            "plus_scope": " ".join(GooglePlusAuth.DEFAULT_SCOPE),
            "available_backends": load_backends(settings.AUTHENTICATION_BACKENDS),
        },
        **extra
    )
开发者ID:Byteme8199,项目名称:django-starter,代码行数:9,代码来源:views.py


示例20: context

def context(**extra):
    '''
    python-social-auth 中用于第三方注册携带信息的重写了的 context
    '''
    return dict({
        'plus_id': getattr(settings, 'SOCIAL_AUTH_GOOGLE_PLUS_KEY', None),
        'plus_scope': ' '.join(GooglePlusAuth.DEFAULT_SCOPE),
        'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS)
    }, **extra)
开发者ID:lalahahaane,项目名称:cx-blog,代码行数:9,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python db.get_slice函数代码示例发布时间:2022-05-27
下一篇:
Python views.complete函数代码示例发布时间: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