Example #1
0
 def clean_redirect_url(self):
     url = self.cleaned_data['redirect_url'].strip()
     if url:
         # Ensure URL is not to a different host
         host = urlparse.urlparse(url)[1]
         if host and host == self.host:
             return url
Example #2
0
 def clean_redirect_url(self):
     url = self.cleaned_data["redirect_url"].strip()
     if url:
         # Ensure URL is not to a different host
         host = urlparse.urlparse(url)[1]
         if host and host == self.host:
             return url
Example #3
0
 def clean_redirect_url(self):
     url = self.cleaned_data['redirect_url'].strip()
     if not url:
         return settings.LOGIN_REDIRECT_URL
     host = urlparse.urlparse(url)[1]
     if host and host != self.host:
         return settings.LOGIN_REDIRECT_URL
     return url
Example #4
0
 def clean_redirect_url(self):
     url = self.cleaned_data["redirect_url"].strip()
     if not url:
         return settings.LOGIN_REDIRECT_URL
     host = urlparse.urlparse(url)[1]
     if host and host != self.host:
         return settings.LOGIN_REDIRECT_URL
     return url
Example #5
0
    def _checklogin(request, *args, **kwargs):
        if request.user.is_active and request.user.is_staff:
            return view_func(request, *args, **kwargs)

        # If user is not logged in, redirect to login page
        if not request.user.is_authenticated():
            # If the login url is the same scheme and net location then just
            # use the path as the "next" url.
            path = request.build_absolute_uri()
            login_scheme, login_netloc = urlparse.urlparse(login_url)[:2]
            current_scheme, current_netloc = urlparse.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()

            messages.warning(request, _("You must log in to access this page"))
            return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME)
        else:
            # User does not have permission to view this page
            raise PermissionDenied
Example #6
0
    def _checklogin(request, *args, **kwargs):
        if request.user.is_active and request.user.is_staff:
            return view_func(request, *args, **kwargs)

        # If user is not logged in, redirect to login page
        if not request.user.is_authenticated():
            # If the login url is the same scheme and net location then just
            # use the path as the "next" url.
            path = request.build_absolute_uri()
            login_scheme, login_netloc = urlparse.urlparse(login_url)[:2]
            current_scheme, current_netloc = urlparse.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()

            messages.warning(request, _("You must log in to access this page"))
            return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME)
        else:
            # User does not have permission to view this page
            raise PermissionDenied
Example #7
0
 def get_success_url(self):
     url = None
     if self.request.POST.get('next'):
         url = self.request.POST.get('next')
     elif 'HTTP_REFERER' in self.request.META:
         url = self.request.META['HTTP_REFERER']
     if url:
         # We only allow internal URLs so we see if the url resolves
         try:
             resolve(urlparse.urlparse(url).path)
         except Http404:
             url = None
     if url is None:
         url = reverse('basket:summary')
     return url
Example #8
0
 def get_success_url(self):
     url = None
     if self.request.POST.get('next'):
         url = self.request.POST.get('next')
     elif 'HTTP_REFERER' in self.request.META:
         url = self.request.META['HTTP_REFERER']
     if url:
         # We only allow internal URLs so we see if the url resolves
         try:
             resolve(urlparse.urlparse(url).path)
         except Http404:
             url = None
     if url is None:
         url = reverse('basket:summary')
     return url
Example #9
0
def get_back_button(context):
    """
    Show back button, custom title available for different urls, for
    example 'Back to search results', no back button if user came from other
    site
    """
    request = context.get('request', None)
    if not request:
        raise Exception('Cannot get request from context')

    referrer = request.META.get('HTTP_REFERER', None)
    if not referrer:
        return None

    try:
        url = urlparse.urlparse(referrer)
    except:
        return None

    if request.get_host() != url.netloc:
        try:
            Site.objects.get(domain=url.netloc)
        except Site.DoesNotExist:
            # Came from somewhere else, don't show back button:
            return None

    try:
        match = resolve(url.path)
    except Resolver404:
        return None

    # This dict can be extended to link back to other browsing pages
    titles = {
        'search:search': _('Back to search results'),
    }
    title = titles.get(match.view_name, None)

    if title is None:
        return None

    return {'url': referrer, 'title': six.text_type(title), 'match': match}
Example #10
0
def get_back_button(context):
    """
    Show back button, custom title available for different urls, for
    example 'Back to search results', no back button if user came from other
    site
    """
    request = context.get('request', None)
    if not request:
        raise Exception('Cannot get request from context')

    referrer = request.META.get('HTTP_REFERER', None)
    if not referrer:
        return None

    try:
        url = urlparse.urlparse(referrer)
    except:
        return None

    if request.get_host() != url.netloc:
        try:
            Site.objects.get(domain=url.netloc)
        except Site.DoesNotExist:
            # Came from somewhere else, don't show back button:
            return None

    try:
        match = resolve(url.path)
    except Resolver404:
        return None

    # This dict can be extended to link back to other browsing pages
    titles = {
        'search:search': _('Back to search results'),
    }
    title = titles.get(match.view_name, None)

    if title is None:
        return None

    return {'url': referrer, 'title': six.text_type(title), 'match': match}