def get(self):

        """Display page to enter access code"""

        # if valid session, then redirect to welcome page
        if 'valid_user' in self.session:
            if self.session['valid_user'] is True:
                return self.redirect_to('welcome')

        template_values = {
            'cur_page': 'welcome',
            'csrf_token': BaseHandler.generate_csrf_token(self)
        }

        # validate access code if passed into URL
        if self.request.get('c'):
            is_valid = BaseHandler.validate_access_code(self, self.request.get('c'))

            # if access code is valid, redirect to Welcome page
            if is_valid is True:
                return self.redirect_to('welcome')
            else:
                template_values['code_attempted'] = True

        template = jinja_env.get_template('gate.html')
        self.response.out.write(template.render(template_values))
    def post(self):

        """Process access code entry"""

        # if webapp2.get_app().debug is not True:
            # if 'valid_user' in self.session:
            #     if self.session['valid_user'] is True:
            #         return self.redirect('/')

        # get language content for Enter page
        l10n = BaseHandler.get_page_content(self, 'enter')

        template_values = {
            'cur_page': 'gate',
            'l10n': l10n,
            'code_attempted': True,
            'csrf_token': BaseHandler.generate_csrf_token(self),
            'language_code': BaseHandler.get_language(self)
        }

        is_valid = BaseHandler.validate_access_code(self, self.request.get('c'))

        if is_valid is True:
            return self.redirect_to('home')

        # re-display access code entry form
        template = jinja_env.get_template('enter.html')
        self.response.out.write(template.render(template_values))
    def post(self):

        """Process access code entry"""

        if 'valid_user' in self.session:
            if self.session['valid_user'] is True:
                return self.redirect_to('welcome')

        template_values = {
            'cur_page': 'welcome',
            'code_attempted': True,
            'csrf_token': BaseHandler.generate_csrf_token(self)
        }

        is_valid = BaseHandler.validate_access_code(self, self.request.get('c'))

        if is_valid is True:
            return self.redirect_to('welcome')

        # re-display access code entry form
        template = jinja_env.get_template('gate.html')
        self.response.out.write(template.render(template_values))