本文整理汇总了Python中social_auth.backends.get_backend函数的典型用法代码示例。如果您正苦于以下问题:Python get_backend函数的具体用法?Python get_backend怎么用?Python get_backend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_backend函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError(
"Incorrect authentication " + "service or service API settings not available!"
)
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
if RAISE_EXCEPTIONS:
raise
backend_name = backend.AUTH_BACKEND.name
log("error", unicode(e), exc_info=True, extra=dict(request=request))
if "django.contrib.messages" in setting("INSTALLED_APPS"):
from django.contrib.messages.api import error
error(request, unicode(e), extra_tags=backend_name)
else:
log("warn", "Messages framework not in place, some " + "errors have not been shown to the user.")
url = backend_setting(backend, "SOCIAL_AUTH_BACKEND_ERROR_URL", LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:festlv,项目名称:django-social-auth,代码行数:30,代码来源:views.py
示例2: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError('Incorrect authentication ' + \
'service')
RAISE_EXCEPTIONS = backend_setting(backend, 'SOCIAL_AUTH_RAISE_EXCEPTIONS', setting('DEBUG'))
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
if RAISE_EXCEPTIONS:
raise
log('error', unicode(e), exc_info=True, extra={
'request': request
})
mod, func_name = PROCESS_EXCEPTIONS.rsplit('.', 1)
try:
process = getattr(import_module(mod), func_name,
lambda *args: None)
except ImportError:
pass
else:
process(request, backend, e)
url = backend_setting(backend, 'SOCIAL_AUTH_BACKEND_ERROR_URL',
LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:1st,项目名称:django-social-auth,代码行数:33,代码来源:decorators.py
示例3: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError('Incorrect authentication ' + \
'service')
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
backend_name = backend.AUTH_BACKEND.name
msg = str(e)
if 'django.contrib.messages' in settings.INSTALLED_APPS:
from django.contrib.messages.api import error
error(request, msg, extra_tags=backend_name)
else:
if ERROR_KEY: # store error in session
request.session[ERROR_KEY] = msg
if NAME_KEY: # store the backend name for convenience
request.session[NAME_KEY] = backend_name
return HttpResponseRedirect(BACKEND_ERROR_REDIRECT)
开发者ID:od-eon,项目名称:django-social-auth,代码行数:26,代码来源:views.py
示例4: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError("Incorrect authentication " + "service")
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
backend_name = backend.AUTH_BACKEND.name
logger.error(unicode(e), exc_info=True, extra=dict(request=request))
# Why!?
msg = str(e)
if "django.contrib.messages" in settings.INSTALLED_APPS:
from django.contrib.messages.api import error
error(request, msg, extra_tags=backend_name)
else:
logger.warn("Messages framework not in place, some " + "errors have not been shown to the user.")
return HttpResponseRedirect(BACKEND_ERROR_REDIRECT)
开发者ID:alexlovelltroy,项目名称:django-social-auth,代码行数:27,代码来源:views.py
示例5: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError('Incorrect authentication ' + \
'service')
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
if setting('DEBUG'):
raise
backend_name = backend.AUTH_BACKEND.name
log('error', unicode(e), exc_info=True,
extra=dict(request=request))
if 'django.contrib.messages' in setting('INSTALLED_APPS'):
from django.contrib.messages.api import error
error(request, unicode(e), extra_tags=backend_name)
else:
log('warn', 'Messages framework not in place, some '+
'errors have not been shown to the user.')
url = setting('SOCIAL_AUTH_BACKEND_ERROR_URL', LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:FrankBie,项目名称:django-social-auth,代码行数:30,代码来源:views.py
示例6: associate_complete
def associate_complete(request, backend):
"""Authentication complete process"""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
backend.auth_complete(user=request.user)
url = request.session.pop(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT
return HttpResponseRedirect(url)
开发者ID:jess3,项目名称:django-social-auth,代码行数:8,代码来源:views.py
示例7: disconnect
def disconnect(request, backend):
"""Disconnects given backend from current logged in user."""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError("Incorrect authentication service")
backend.disconnect(request.user)
url = request.REQUEST.get(REDIRECT_FIELD_NAME, "") or DEFAULT_REDIRECT
return HttpResponseRedirect(url)
开发者ID:statico,项目名称:django-social-auth,代码行数:8,代码来源:views.py
示例8: associate_complete
def associate_complete(request, backend):
"""Authentication complete process"""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError("Incorrect authentication service")
backend.auth_complete(user=request.user)
url = request.session.pop(REDIRECT_FIELD_NAME, "") or getattr(settings, "LOGIN_REDIRECT_URL", "")
return HttpResponseRedirect(url)
开发者ID:orygens,项目名称:django-social-auth,代码行数:8,代码来源:views.py
示例9: disconnect
def disconnect(request, backend):
"""Disconnects given backend from current logged in user."""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
backend.disconnect(request.user)
url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or \
getattr(settings, 'LOGIN_REDIRECT_URL', '')
return HttpResponseRedirect(url)
开发者ID:justquick,项目名称:django-social-auth,代码行数:9,代码来源:views.py
示例10: disconnect
def disconnect(request, backend, association_id=None):
"""Disconnects given backend from current logged in user."""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
backend.disconnect(request.user, association_id)
url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or \
DISCONNECT_REDIRECT_URL or \
DEFAULT_REDIRECT
return HttpResponseRedirect(url)
开发者ID:cid2105,项目名称:greek_gavel,代码行数:10,代码来源:views.py
示例11: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError("Incorrect authentication " + "service")
return func(request, backend, *args, **kwargs)
开发者ID:szaboat,项目名称:django-social-auth,代码行数:10,代码来源:views.py
示例12: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
request.social_auth_backend = get_backend(backend, request,
redirect)
if request.social_auth_backend is None:
raise WrongBackend(backend)
return func(request, request.social_auth_backend, *args, **kwargs)
开发者ID:Kayle009,项目名称:sentry,代码行数:10,代码来源:decorators.py
示例13: auth_process
def auth_process(request, backend, complete_url_name, default_final_url):
"""Authenticate using social backend"""
redirect = reverse(complete_url_name, args=(backend,))
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError("Incorrect authentication service")
request.session[REDIRECT_FIELD_NAME] = request.GET.get(REDIRECT_FIELD_NAME, default_final_url)
if backend.uses_redirect:
return HttpResponseRedirect(backend.auth_url())
else:
return HttpResponse(backend.auth_html(), content_type="text/html;charset=UTF-8")
开发者ID:orygens,项目名称:django-social-auth,代码行数:11,代码来源:views.py
示例14: complete
def complete(request, backend):
"""Authentication complete process"""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError("Incorrect authentication service")
user = backend.auth_complete()
if user and getattr(user, "is_active", True):
login(request, user)
url = request.session.pop(REDIRECT_FIELD_NAME, "") or getattr(settings, "LOGIN_REDIRECT_URL", "")
else:
url = getattr(settings, "LOGIN_ERROR_URL", settings.LOGIN_URL)
return HttpResponseRedirect(url)
开发者ID:orygens,项目名称:django-social-auth,代码行数:12,代码来源:views.py
示例15: complete_process
def complete_process(request, backend):
"""Authentication complete process"""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError("Incorrect authentication service")
try:
user = backend.auth_complete()
except ValueError, e: # some Authentication error ocurred
user = None
error_key = getattr(settings, "SOCIAL_AUTH_ERROR_KEY", None)
if error_key: # store error in session
request.session[error_key] = str(e)
开发者ID:statico,项目名称:django-social-auth,代码行数:13,代码来源:views.py
示例16: auth_complete
def auth_complete(request, backend):
"""Complete auth process. Return authenticated user or None."""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
user = request.user if request.user.is_authenticated() else None
try:
user = backend.auth_complete(user=user)
except ValueError, e: # some Authentication error ocurred
error_key = getattr(settings, 'SOCIAL_AUTH_ERROR_KEY', None)
if error_key: # store error in session
request.session[error_key] = str(e)
开发者ID:cid2105,项目名称:greek_gavel,代码行数:14,代码来源:views.py
示例17: auth_process
def auth_process(request, backend, complete_url_name):
"""Authenticate using social backend"""
redirect = reverse(complete_url_name, args=(backend,))
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError("Incorrect authentication service")
data = request.REQUEST
# Check and sanitize a user-defined GET/POST redirect_to field value.
redirect = sanitize_redirect(request.get_host(), data.get(REDIRECT_FIELD_NAME))
request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT
if backend.uses_redirect:
return HttpResponseRedirect(backend.auth_url())
else:
return HttpResponse(backend.auth_html(), content_type="text/html;charset=UTF-8")
开发者ID:statico,项目名称:django-social-auth,代码行数:14,代码来源:views.py
示例18: delete
def delete(self, request, user, identity_id):
"""
Disconnect a Identity from Account
```````````````````````````````````````````````````````
Disconnects a social auth identity from a sentry account
:pparam string identity_id: identity id
:auth: required
"""
try:
auth = UserSocialAuth.objects.get(id=identity_id)
except UserSocialAuth.DoesNotExist:
return Response(status=404)
backend = get_backend(auth.provider, request, '/')
if backend is None:
raise Exception(u'Backend was not found for request: {}'.format(auth.provider))
# stop this from bubbling up errors to social-auth's middleware
# XXX(dcramer): IM SO MAD ABOUT THIS
try:
backend.disconnect(user, identity_id)
except Exception as exc:
import sys
exc_tb = sys.exc_info()[2]
six.reraise(Exception, exc, exc_tb)
del exc_tb
# XXX(dcramer): we experienced an issue where the identity still existed,
# and given that this is a cheap query, lets error hard in that case
assert not UserSocialAuth.objects.filter(
user=user,
id=identity_id,
).exists()
logger.info(
'user.identity.disconnect',
extra={
'user_id': user.id,
'ip_address': request.META['REMOTE_ADDR'],
'usersocialauth_id': identity_id,
}
)
return Response(status=204)
开发者ID:Kayle009,项目名称:sentry,代码行数:47,代码来源:user_social_identity_details.py
示例19: disconnect_identity
def disconnect_identity(request, identity_id):
if request.method != 'POST':
raise NotImplementedError
try:
auth = UserSocialAuth.objects.get(id=identity_id)
except UserSocialAuth.DoesNotExist:
return HttpResponseRedirect(reverse('sentry-account-settings-identities'))
backend = get_backend(auth.provider, request, '/')
if backend is None:
raise Exception('Backend was not found for request: {}'.format(auth.provider))
# stop this from bubbling up errors to social-auth's middleware
# XXX(dcramer): IM SO MAD ABOUT THIS
try:
backend.disconnect(request.user, identity_id)
except Exception as exc:
import sys
exc_tb = sys.exc_info()[2]
six.reraise(Exception, exc, exc_tb)
del exc_tb
# XXX(dcramer): we experienced an issue where the identity still existed,
# and given that this is a cheap query, lets error hard in that case
assert not UserSocialAuth.objects.filter(
user=request.user,
id=identity_id,
).exists()
backend_name = backend.AUTH_BACKEND.name
messages.add_message(
request, messages.SUCCESS, 'Your {} identity has been disconnected.'.format(
settings.AUTH_PROVIDER_LABELS.get(backend_name, backend_name),
)
)
logger.info(
'user.identity.disconnect',
extra={
'user_id': request.user.id,
'ip_address': request.META['REMOTE_ADDR'],
'usersocialauth_id': identity_id,
}
)
return HttpResponseRedirect(reverse('sentry-account-settings-identities'))
开发者ID:hosmelq,项目名称:sentry,代码行数:46,代码来源:accounts.py
示例20: new_user_social_auth
def new_user_social_auth(request, backend, username, email=None, template="registration/association.html",
form_class_login=AuthenticationForm, form_class_register=RegistrationForm, *args, **kwargs):
"""Complete auth process. Return authenticated user or None."""
new_data = {}
if request.user and request.user.is_authenticated():
new_data['user'] = request.user
if 'register' in request.POST:
form_register = form_class_register(request.POST)
form_login = form_class_login(request)
if form_register.is_valid():
new_data['username'] = form_register.cleaned_data['username']
new_data['user'] = UserSocialAuth.create_user(form_register.cleaned_data['username'],
form_register.cleaned_data['email'],
form_register.cleaned_data['password1'])
else:
initial_data = { 'username': username }
if email:
initial_data.update({ 'email': email })
form_register = form_class_register(initial=initial_data)
form_login = form_class_login(request, request.POST or None)
if form_login.is_valid():
new_data['user'] = form_login.get_user()
if new_data:
if request.session.get(PIPELINE_KEY):
data = request.session.pop(PIPELINE_KEY)
backend = get_backend(backend, request, '/')
idx, xargs, xkwargs = backend.from_session_dict(data, *args, **kwargs)
xkwargs.update(new_data)
data = backend.to_session_dict(idx, *xargs, **xkwargs)
request.session[PIPELINE_KEY] = data
return complete_process(request, backend, *args, **kwargs)
context = {
'form_register': form_register,
'form_login': form_login,
'backend': backend,
}
return TemplateResponse(request, template, context)
开发者ID:MatvilCorp,项目名称:etvnet.oauth2,代码行数:42,代码来源:views.py
注:本文中的social_auth.backends.get_backend函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论