Ejemplo n.º 1
0
    def get_next_page(self):
        if self.next_page is not None:
            next_page = resolve_url(self.next_page)
        elif settings.LOGOUT_REDIRECT_URL:
            next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)
        else:
            next_page = self.next_page

        if (self.redirect_field_name in self.request.POST
                or self.redirect_field_name in self.request.GET):
            next_page = self.request.POST.get(
                self.redirect_field_name,
                self.request.GET.get(self.redirect_field_name))
            url_is_safe = is_safe_url(
                url=next_page,
                allowed_hosts=self.get_success_url_allowed_hosts(),
                require_https=self.request.is_secure(),
            )
            # Security check -- Ensure the user-originating redirection URL is
            # safe.
            if not url_is_safe:
                next_page = self.request.path
        return next_page
Ejemplo n.º 2
0
 def _wrapped_view(request, *args, **kwargs):
     if test_func(request.user):
         return view_func(request, *args, **kwargs)
     path = request.build_absolute_uri()
     resolved_login_url = resolve_url(login_url or settings.LOGIN_URL)
     # If the login url is the same scheme and net location then just
     # use the path as the "next" url.
     login_scheme, login_netloc = urlparse(resolved_login_url)[:2]
     current_scheme, current_netloc = urlparse(path)[:2]
     if ((not login_scheme or login_scheme == current_scheme)
             and (not login_netloc or login_netloc == current_netloc)):
         path = request.get_full_path()
     from server.contrib.auth.views import redirect_to_login
     return redirect_to_login(path, resolved_login_url,
                              redirect_field_name)
Ejemplo n.º 3
0
def redirect_to_login(next,
                      login_url=None,
                      redirect_field_name=REDIRECT_FIELD_NAME):
    """
    Redirect the user to the login page, passing the given 'next' page.
    """
    resolved_url = resolve_url(login_url or settings.LOGIN_URL)

    login_url_parts = list(urlparse(resolved_url))
    if redirect_field_name:
        querystring = QueryDict(login_url_parts[4], mutable=True)
        querystring[redirect_field_name] = next
        login_url_parts[4] = querystring.urlencode(safe='/')

    return HttpResponseRedirect(urlunparse(login_url_parts))
Ejemplo n.º 4
0
 def get_success_url(self):
     url = self.get_redirect_url()
     return url or resolve_url(settings.LOGIN_REDIRECT_URL)
Ejemplo n.º 5
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['login_url'] = resolve_url(settings.LOGIN_URL)
     return context
Ejemplo n.º 6
0
def logout_then_login(request, login_url=None):
    """
    Log out the user if they are logged in. Then redirect to the login page.
    """
    login_url = resolve_url(login_url or settings.LOGIN_URL)
    return LogoutView.as_view(next_page=login_url)(request)