Edgewall Software

Ticket #540: 540-login-redirect-r7414.patch

File 540-login-redirect-r7414.patch, 1.4 KB (added by Remy Blank <remy.blank@…>, 4 years ago)

Patch against 0.11-stable adding redirection of URLs below /login

  • trac/web/auth.py

    diff --git a/trac/web/auth.py b/trac/web/auth.py
    a b  
    3535from trac.web.api import IAuthenticator, IRequestHandler 
    3636from trac.web.chrome import INavigationContributor 
    3737from trac.util import hex_entropy, md5, md5crypt 
     38from trac.util.text import unicode_urlencode 
    3839 
    3940 
    4041class LoginModule(Component): 
     
    9495    # IRequestHandler methods 
    9596 
    9697    def match_request(self, req): 
    97         return re.match('/(login|logout)/?$', req.path_info) 
     98        return re.match('/(?:login(?:/.*|$)|logout/?$)', req.path_info) 
    9899 
    99100    def process_request(self, req): 
    100101        if req.path_info.startswith('/login'): 
    101102            self._do_login(req) 
     103            if len(req.path_info) > 7: 
     104                self._redirect_args(req, req.path_info[6:], req.args) 
    102105        elif req.path_info.startswith('/logout'): 
    103106            self._do_logout(req) 
    104107        self._redirect_back(req) 
     
    195198 
    196199        return row[0] 
    197200 
     201    def _redirect_args(self, req, dest, args): 
     202        """Redirect to the given URL with the given arguments.""" 
     203        dest = req.base_path + dest 
     204        if args: 
     205            dest += "?" + unicode_urlencode((k, v)  
     206                for k in args.iterkeys() for v in args.getlist(k)) 
     207        req.redirect(dest) 
     208         
    198209    def _redirect_back(self, req): 
    199210        """Redirect the user back to the URL she came from.""" 
    200211        referer = req.get_header('Referer')