<s> from django . conf import settings <EOL> from django . http import HttpResponseRedirect <EOL> from django . utils . cache import patch_cache_control <EOL> LOGIN_REQUIRED_PREFIXES = getattr ( settings , '<STR_LIT>' , ( ) ) <EOL> NO_LOGIN_REQUIRED_PREFIXES = getattr ( settings , <EOL> '<STR_LIT>' , ( ) ) <EOL> ALLOWED_DOMAINS = getattr ( settings , '<STR_LIT>' , None ) <EOL> NON_REDIRECTED_PATHS = getattr ( settings , '<STR_LIT>' , ( ) ) <EOL> NON_REDIRECTED_BASE_PATHS = tuple ( path . rstrip ( '<STR_LIT:/>' ) + '<STR_LIT:/>' <EOL> for path in NON_REDIRECTED_PATHS ) <EOL> class LoginRequiredMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_request ( self , request ) : <EOL> for prefix in NO_LOGIN_REQUIRED_PREFIXES : <EOL> if request . path . startswith ( prefix ) : <EOL> return None <EOL> for prefix in LOGIN_REQUIRED_PREFIXES : <EOL> if request . path . startswith ( prefix ) and not request . user . is_authenticated ( ) : <EOL> from django . contrib . auth . views import redirect_to_login <EOL> return redirect_to_login ( request . get_full_path ( ) ) <EOL> return None <EOL> class RedirectMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_request ( self , request ) : <EOL> host = request . get_host ( ) . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> if ( settings . DEBUG or host == '<STR_LIT>' or <EOL> not ALLOWED_DOMAINS or <EOL> request . META . get ( '<STR_LIT>' ) == '<STR_LIT:true>' or <EOL> request . path . startswith ( '<STR_LIT>' ) or <EOL> request . path in NON_REDIRECTED_PATHS or <EOL> request . path . startswith ( NON_REDIRECTED_BASE_PATHS ) ) : <EOL> return <EOL> if host not in settings . ALLOWED_DOMAINS : <EOL> return HttpResponseRedirect ( <EOL> '<STR_LIT>' + settings . ALLOWED_DOMAINS [ <NUM_LIT:0> ] + request . path ) <EOL> class NoHistoryCacheMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_response ( self , request , response ) : <EOL> if '<STR_LIT>' not in response and '<STR_LIT>' not in response and hasattr ( request , '<STR_LIT>' ) and request . user . is_authenticated ( ) : <EOL> patch_cache_control ( response , <EOL> no_store = True , no_cache = True , must_revalidate = True , max_age = <NUM_LIT:0> ) <EOL> return response </s>
