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