Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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 get(self, language):
        """Set language for the session based on language code appended to url"""
        valid_languages = BaseHandler.get_languages(self)

        if language in valid_languages:
            BaseHandler.set_language(self, language)

        self.redirect_to('home')
    def get(self):
        """Change the site language"""

        new_language = self.request.get('language')

        BaseHandler.set_language(self, new_language)

        # redirect user back to their previous page
        self.redirect(self.request.referer)
    def get(self):
        """Display the Home page"""

        template_values = {
            # declare template values here
            'l10n': BaseHandler.get_content(self, 'home'),
            'data': BaseHandler.get_data_variables(self),
            'boom': BaseHandler.get_language(self)
        }

        # load the home page template
        template = jinja_env.get_template('index.html')

        # display page
        self.response.out.write(template.render(template_values))
Exemplo n.º 6
0
    def get(self):

        """Display the Home page"""

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

        user_type = BaseHandler.get_user_type(self)

        template_values = {
            'cur_page': 'home',
            'l10n': l10n,
            'user_type': user_type,
            'language_code': BaseHandler.get_language(self)
        }

        # load the welcome page template
        template = jinja_env.get_template('home.html')

        # display page
        self.response.out.write(template.render(template_values))
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
    def get(self):

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

        # if valid session, then redirect to welcome page
        # only perform this check if we're in not debug mode
        # 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,
            'csrf_token': BaseHandler.generate_csrf_token(self),
            'language_code': BaseHandler.get_language(self)
        }

        template = jinja_env.get_template('enter.html')
        self.response.out.write(template.render(template_values))
Exemplo n.º 9
0
    def get(self):

        """Display the Registration form for the first time"""

        form = forms.RegistrationForm()

        template_values = {
            'cur_page': 'register',
            'form': form,
            # 'user_type': self.session['user_type'],
            'csrf_token': BaseHandler.generate_csrf_token(self),
        }

        template = jinja_env.get_template('register.html')

        self.response.out.write(template.render(template_values))
Exemplo n.º 10
0
    def post(self):

        """Validate the submitted Registration form

        If data is invalid, re-display form with errors.
        If data is valid, save data to db and re-direct to confirmation page.
        """

        template_values = {
            'cur_page': 'register',
            # 'user_type': self.session['user_type'],
            'csrf_token': BaseHandler.generate_csrf_token(self)
        }

        form = forms.RegistrationForm(self.request.POST)

        if self.request.method == 'POST' and form.validate():
            # process valid data

            # create new record
            registration = models.Registration()

            registration.first_name = form.first_name.data
            registration.last_name = form.last_name.data
            registration.email = form.email.data
            registration.company = form.company.data
            registration.industry = form.industry.data
            registration.help_with = form.help_with.data
            registration.share_my_info = form.share_my_info.data
            registration.access_code = self.session['access_code']
            # registration.user_type = self.session['user_type']

            """
            # add values specific to the 'agency' user type
            if self.session['user_type'] == 'agency':
                registration.company_brief = form.company_brief.data

                # if image was uploaded, upload the image to blobstore and save URL to db record
                uploaded_file = self.request.get(form.company_image.name)

                if uploaded_file:

                    # api for manipulating images
                    from google.appengine.api import images

                    # api for adding files to Google Cloud Storage
                    from google.appengine.api import files

                    image = images.Image(uploaded_file)

                    # set image type specifics
                    if image.format == images.JPEG:
                        # JPEG settings
                        file_settings = {
                            'suffix': '.jpg',
                            'mime_type': 'image/jpeg'
                        }
                    elif image.format == images.PNG:
                        # PNG settings
                        file_settings = {
                            'suffix': '.png',
                            'mime_type': 'image/png'
                        }
                    elif image.format == images.GIF:
                        # GIF settings
                        file_settings = {
                            'suffix': '.gif',
                            'mime_type': 'image/gif'
                        }

                    # make sure file is a supported image format
                    if file_settings:

                        # create an empty image file
                        writeable_file_name = files.blobstore.create(mime_type=file_settings['mime_type'])

                        # crop to original size (this is a hack so that we can use execute_transforms() to write the image to file)
                        image.crop(0.0, 0.0, 1.0, 1.0)

                        with files.open(writeable_file_name, 'a') as f:
                            f.write(image.execute_transforms())

                        # save file to blobstore
                        files.finalize(writeable_file_name)

                        # get the blob key for the newly created/hosted file
                        blob_key = files.blobstore.get_blob_key(writeable_file_name)

                        # add image url to registration record
                        registration.company_image = images.get_serving_url(blob_key)
            """

            # save registration record to datastore
            registration.put()

            # send a confirmation email to the user

            # =================================================================
            # TODO: Replace sender address with the address that should be used
            # =================================================================

            message = mail.EmailMessage()
            message.sender = "Agency Engage <*****@*****.**>"
            message.to = registration.first_name + " " + registration.last_name + "<" + registration.email + ">"
            message.subject = "Thank you for registering"
            message.body = """
Thank you for registering, %s!

We will send out more details for the event as the date approaches.
            """ % (registration.first_name)

            message.send()

            # re-direct to confirmation page
            return self.redirect('register-complete')
        else:
            # data is invalid, re-display form
            template_values['form'] = form

        # render the page
        template = jinja_env.get_template('register.html')
        self.response.out.write(template.render(template_values))
Exemplo n.º 11
0
    def get(self, language):

        """ Set language for the session based on language code appended to url """

        BaseHandler.set_language(self, language)
        self.redirect_to('home')