本文整理汇总了Python中social.backends.utils.load_backends函数的典型用法代码示例。如果您正苦于以下问题:Python load_backends函数的具体用法?Python load_backends怎么用?Python load_backends使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_backends函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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,
},
)
示例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,
}
)
示例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)
示例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'),
}
)
示例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)
示例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,
},
)
示例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,
},
),
)
示例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,
}
)
示例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()
示例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
示例14: context
def context(**extra):
"""
Adding default context to rendered page.
"""
return dict({
'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS),
}, **extra)
示例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})