def _wrapped_view_func(request, *args, **kwargs): if not request.using_https and not settings.DEBUG: return HttpResponse('{"detail": "This resource requires a secure connection (https)"}', status=403) if not request.user.is_authenticated(): # Quick fix, should be implemented better path = request.build_absolute_uri().split('/apiv2/')[1] path = prepend_base('/apiv2/' + path, use_https=not settings.DEBUG, dynamic_resolve=False) return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME) return view_func(request, *args, **kwargs)
def _wrapped_view_func(request, *args, **kwargs): if not request.using_https and not settings.DEBUG: return HttpResponse('{"detail": "This resource requires a secure connection (https)"}', status=403) # Logout the user so we make sure he needs to login again logout(request) # Quick fix, should be implemented better path = request.build_absolute_uri().split('/apiv2/')[1] path = prepend_base('/apiv2/' + path, use_https=not settings.DEBUG, dynamic_resolve=False) path = path.replace('logout_and_', '') return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME)
from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth.views import redirect_to_login from django.views.decorators.csrf import csrf_exempt from django.http import HttpResponse from apiv2.utils import AccessTokenView, Authorize, Capture, Redirect, prepend_base import settings ''' We create oauth2_urls.py files and then include to the main apiv2/urls.py because we were having namespace problems otherwise. Apparently if namespace is defined manually (ex: name='oauth2:capture'), Django complains. ''' if settings.USE_MINIMAL_TEMPLATES_FOR_OAUTH: login_url = prepend_base('/apiv2/login/', use_https=not settings.DEBUG, dynamic_resolve=False) else: login_url = prepend_base(settings.LOGIN_URL, use_https=not settings.DEBUG, dynamic_resolve=False) def https_and_login_required(view_func): def _wrapped_view_func(request, *args, **kwargs): if not request.using_https and not settings.DEBUG: return HttpResponse('{"detail": "This resource requires a secure connection (https)"}', status=403) if not request.user.is_authenticated(): # Quick fix, should be implemented better path = request.build_absolute_uri().split('/apiv2/')[1] path = prepend_base('/apiv2/' + path, use_https=not settings.DEBUG, dynamic_resolve=False) return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME) return view_func(request, *args, **kwargs)