Пример #1
0
    def process_request(self, request):
        """when askbot is in the closed mode
        it will let through only authenticated users.
        All others will be redirected to the login url.
        """
        if (askbot_settings.ASKBOT_CLOSED_FORUM_MODE
                and request.user.is_anonymous()):
            resolver_match = ResolverMatch(resolve(request.path))

            internal_ips = getattr(settings, 'ASKBOT_INTERNAL_IPS', None)
            if internal_ips and request.META.get(
                    'REMOTE_ADDR') in internal_ips:
                return None

            if is_view_allowed(resolver_match.func):
                return

            if is_view_protected(resolver_match.func):
                request.user.message_set.create(
                    _('Please log in to use %s') % \
                    askbot_settings.APP_SHORT_NAME
                )
                redirect_url = '%s?next=%s' % (settings.LOGIN_URL,
                                               urllib.quote_plus(
                                                   request.get_full_path()))
                return HttpResponseRedirect(redirect_url)
        return None
Пример #2
0
def clean_login_url(url):
    """pass through, unless user was originally on the logout page"""
    try:
        resolver_match = ResolverMatch(resolve(url))
        from askbot.views.readers import question
        if resolver_match.func == question:
            return url
    except Http404:
        pass
    return reverse('index')
Пример #3
0
    def process_request(self, request):
        """when askbot is in the closed mode
        it will let through only authenticated users.
        All others will be redirected to the login url.
        """
        if (askbot_settings.ASKBOT_CLOSED_FORUM_MODE
                and request.user.is_anonymous()):
            resolver_match = ResolverMatch(resolve(request.path))

            if is_view_allowed(resolver_match.func):
                return

            if is_view_protected(resolver_match.func):
                request.user.message_set.create(
                    _('Please log in to use %s') % \
                    askbot_settings.APP_SHORT_NAME
                )
                return HttpResponseRedirect(settings.LOGIN_URL)
        return None