Changeset 8818


Ignore:
Timestamp:
18/10/13 09:42:35 (5 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

Update the index page with login information

File:
1 edited

Legend:

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

    r8813 r8818  
    7272    request.session['accountid'] = userid 
    7373 
     74def is_public_url(request): 
     75    url_fiters = getattr(settings, 'DJ_SECURITY_FILTER', []) 
     76     
     77    #adds a default filter for reset password request 
     78    reset_regexpr = '%s=[a-f0-9-]*$' % (token_field_name()) 
     79    if reset_regexpr not in security_filter():  
     80        url_fiters.append(reset_regexpr) 
     81         
     82    if url_fiters \ 
     83        and filter(_build_url(request), url_fiters): 
     84        return True 
     85    return False     
     86 
    7487class DJ_Security_Middleware(object): 
    7588    """ 
     
    90103            return response 
    91104 
    92         request.session['accountid'] = None 
    93         url_fiters = getattr(settings, 'DJ_SECURITY_FILTER', []) 
    94          
    95         #adds a default filter for reset password request 
    96         reset_regexpr = '%s=[a-f0-9-]*$' % (token_field_name()) 
    97         if reset_regexpr not in security_filter():  
    98             url_fiters.append(reset_regexpr) 
    99          
    100         if url_fiters \ 
    101             and filter(_build_url(request), url_fiters): 
    102             return 
    103          
    104105        custom_auth = getattr(settings, 'DJ_SECURITY_AUTH_CHECK', None) 
    105106        if custom_auth: 
     
    126127                                      tokens,  
    127128                                      user_data) 
    128         except MissingCookieException as ex: 
    129             LOGGER.info("Missing cookie '%s'. Redirecting to %s" % (auth_tkt_name(), url)) 
    130             return HttpResponseRedirect(url) 
    131         except DJMiddlewareException as ex:                     
    132             LOGGER.info("Error in authentication. Redirecting to %s" % (url)) 
    133             return HttpResponseRedirect(url)            
     129            log_msg = '' 
     130        except MissingCookieException: 
     131            log_msg = "Missing cookie '%s'. Redirecting to %s" % (auth_tkt_name(), url) 
     132        except DJMiddlewareException:                   
     133            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: 
     138                LOGGER.info(log_msg) 
     139                return HttpResponseRedirect(url)                            
    134140 
    135141 
Note: See TracChangeset for help on using the changeset viewer.