src/cm/middleware.py
author Simon Descarpentries <sid@sopinspace.com>
Wed, 09 May 2012 17:13:33 +0200
changeset 417 c5e91f204371
parent 285 1070d52adc11
child 475 782d40ecf7c3
permissions -rw-r--r--
After investigations, commit the proposed patch by kklimonda presented with the following introduction : cm/templates/site/login_form.html template uses a relative url for the form action, which seems to break deployment in the subfolder when trailing slash is missing (the form redirects to the upper folder breaking login). Using {% url login %} (as in the attached patch) instead would fix the issue.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
from cm.exception import UnauthorizedException 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
from django.conf import settings
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
from django.http import HttpResponseServerError,HttpResponseRedirect
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
from django.core.urlresolvers import reverse
285
1070d52adc11 propagates query string parameters when login in (so that link with direct coment id are properly propagated)
raph
parents: 0
diff changeset
     5
from urllib import urlencode
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     6
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     7
class CmMiddleware(object):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     8
    
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     9
    def process_exception(self, request, exception):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    10
        if settings.DEBUG:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    11
            import sys, traceback
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    12
            traceback.print_exc()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    13
        if type(exception) == UnauthorizedException:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    14
            if request.user.is_anonymous():
285
1070d52adc11 propagates query string parameters when login in (so that link with direct coment id are properly propagated)
raph
parents: 0
diff changeset
    15
                query = urlencode({'next': request.META['PATH_INFO'], 'q' : request.META['QUERY_STRING'] })
1070d52adc11 propagates query string parameters when login in (so that link with direct coment id are properly propagated)
raph
parents: 0
diff changeset
    16
                login_url = reverse('login') + '?'  + query
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    17
                return HttpResponseRedirect(login_url)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    18
            else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    19
                redirect_url = reverse('unauthorized')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    20
                return HttpResponseRedirect(redirect_url)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    21
        raise