<s> from __future__ import absolute_import , unicode_literals <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import Http404 , HttpResponse <EOL> from django . shortcuts import get_object_or_404 , redirect <EOL> from wagtail . wagtailcore import hooks <EOL> from wagtail . wagtailcore . forms import PasswordPageViewRestrictionForm <EOL> from wagtail . wagtailcore . models import Page , PageViewRestriction <EOL> def serve ( request , path ) : <EOL> if not request . site : <EOL> raise Http404 <EOL> path_components = [ component for component in path . split ( '<STR_LIT:/>' ) if component ] <EOL> page , args , kwargs = request . site . root_page . specific . route ( request , path_components ) <EOL> for fn in hooks . get_hooks ( '<STR_LIT>' ) : <EOL> result = fn ( page , request , args , kwargs ) <EOL> if isinstance ( result , HttpResponse ) : <EOL> return result <EOL> return page . serve ( request , * args , ** kwargs ) <EOL> def authenticate_with_password ( request , page_view_restriction_id , page_id ) : <EOL> """<STR_LIT>""" <EOL> restriction = get_object_or_404 ( PageViewRestriction , id = page_view_restriction_id ) <EOL> page = get_object_or_404 ( Page , id = page_id ) . specific <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = PasswordPageViewRestrictionForm ( request . POST , instance = restriction ) <EOL> if form . is_valid ( ) : <EOL> has_existing_session = ( settings . SESSION_COOKIE_NAME in request . COOKIES ) <EOL> passed_restrictions = request . session . setdefault ( '<STR_LIT>' , [ ] ) <EOL> if restriction . id not in passed_restrictions : <EOL> passed_restrictions . append ( restriction . id ) <EOL> request . session [ '<STR_LIT>' ] = passed_restrictions <EOL> if not has_existing_session : <EOL> request . session . set_expiry ( <NUM_LIT:0> ) <EOL> return redirect ( form . cleaned_data [ '<STR_LIT>' ] ) <EOL> else : <EOL> form = PasswordPageViewRestrictionForm ( instance = restriction ) <EOL> action_url = reverse ( '<STR_LIT>' , args = [ restriction . id , page . id ] ) <EOL> return page . serve_password_required_response ( request , form , action_url ) </s>
