root/authrequiredplugin/0.10/tracauthrequired/authrequired.py

Revision 2462, 2.5 kB (checked in by BladeHawke, 1 year ago)

AuthRequiredPlugin:

Removed spurious self.env.href() that caused redirection issues on trac installation not at root of vhost. (fixes #1771)

Line 
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright 2006 Anton Graham <bladehawke@gmail.com>
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 #  1. Redistributions of source code must retain the above copyright
11 #     notice, this list of conditions and the following disclaimer.
12 #  2. Redistributions in binary form must reproduce the above copyright
13 #     notice, this list of conditions and the following disclaimer in
14 #     the documentation and/or other materials provided with the
15 #     distribution.
16 #  3. The name of the author may not be used to endorse or promote
17 #     products derived from this software without specific prior
18 #     written permission.
19
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 from trac.core import *
33 from trac.web.chrome import INavigationContributor
34
35 class AuthRequired(Component):
36     """AuthRequiredPlugin
37     Require anonymous users to authenticate using the form based login.
38     This has been greatly simplified from the original implementation
39     thanks to a hint from coderanger.
40        """
41     implements(INavigationContributor)
42
43     # INavigationContributor methods
44
45     def get_active_navigation_item(self, req):
46         return 'AuthRequired'
47
48     def get_navigation_items(self, req):
49         if ((req.authname and req.authname != 'anonymous') or \
50             req.path_info.startswith('/login') or \
51             req.path_info.startswith('/reset_password') or \
52             req.path_info.startswith('/register')):
53             return []
54         self.log.debug('Redirecting anonymous request to /login')
55         #req.redirect(req.href.login())
56         # Testing new redirect syntax.  Thanks to jfernandez@ist.psu.edu
57         req.redirect(req.href.login(), {'referer':req.abs_href(req.path_info)})
58         return [] # We don't really get here, but what the heck...
Note: See TracBrowser for help on using the browser.