Changeset 8819


Ignore:
Timestamp:
18/10/13 10:43:41 (6 years ago)
Author:
mnagni
Message:

Incomplete - # 22919: [CEDA Site Python Port] Resource Registration - show breadcrumbs and logged in status
 http://team.ceda.ac.uk/trac/ceda/ticket/22919

Implements the logged status in the public pages as 'index'
Implements the login button for the public pages

moved to version 0.0.20

Location:
mauRepo/dj_security_middleware/trunk/dj_security_middleware
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/__init__.py

    r8815 r8819  
    1 __version__ = '0.0.15' 
     1__version__ = '0.0.20' 
    22 
    33from django.conf import settings 
  • mauRepo/dj_security_middleware/trunk/dj_security_middleware/middleware.py

    r8818 r8819  
    6161 
    6262LOGOUT = 'logout' 
     63LOGIN = 'login' 
    6364 
    6465LOGGER = logging.getLogger(__name__) 
     
    7273    request.session['accountid'] = userid 
    7374 
     75def filter_url(string, filters): 
     76    """ 
     77        Checks a given strings against a list of strings. 
     78        ** string ** string a url 
     79        ** filters ** a list of strings 
     80    """ 
     81    for ifilter in filters: 
     82        if re.search(ifilter, string): 
     83            return True 
     84 
    7485def is_public_url(request): 
    7586    url_fiters = getattr(settings, 'DJ_SECURITY_FILTER', []) 
     
    8192         
    8293    if url_fiters \ 
    83         and filter(_build_url(request), url_fiters): 
     94        and filter_url(_build_url(request), url_fiters): 
    8495        return True 
    8596    return False     
     
    101112            response = HttpResponseRedirect(_build_url(request))             
    102113            response.delete_cookie(auth_tkt_name(), domain = cookie_domain()) 
     114            request.session['accountid'] = None 
    103115            return response 
    104116 
     
    132144        except DJMiddlewareException:                   
    133145            log_msg = "Error in authentication. Redirecting to %s" % (url) 
    134         finally: 
    135             if len(log_msg) == 0 or is_public_url(request): 
    136                 return 
    137             else: 
     146        finally:  
     147            if (len(log_msg) == 0 or is_public_url(request)) \ 
     148                and request.GET.get(LOGIN, None) == None:                     
     149                    return                      
     150            elif len(log_msg) > 0: 
    138151                LOGGER.info(log_msg) 
    139152                return HttpResponseRedirect(url)                            
     
    147160    hostname = socket.getfqdn() 
    148161    new_get = request.GET.copy() 
    149     if new_get.has_key(LOGOUT): 
    150         new_get.pop(LOGOUT) 
     162 
     163    #Removed the LOGIN request attribute as we now know we need to do a login 
     164    new_get.pop(LOGIN, None) 
     165    #Removed the LOGOUT request attribute as we now know we need to do a logout        
     166    new_get.pop(LOGOUT, None) 
     167 
    151168    if request.META['SERVER_PORT'] != 80: 
    152169        hostname = "%s:%s" % (hostname, request.META['SERVER_PORT']) 
     
    175192            raise DJMiddlewareException(ex)  
    176193    raise MissingCookieException(AUTHENTICATION_COOKIE_MISSING)  
    177  
    178 def filter(string, filters): 
    179     """ 
    180         Checks a given strings against a list of strings. 
    181         ** string ** string a url 
    182         ** filters ** a list of strings 
    183     """ 
    184     for ifilter in filters: 
    185         if re.search(ifilter, string): 
    186             return True 
Note: See TracChangeset for help on using the changeset viewer.