Ejemplo n.º 1
0
    def post(self):
        """ validate contact form """

        if not self.form.validate():
            return self.get()
        remoteip = self.request.remote_addr
        user_agent = self.request.user_agent
        exception = self.request.POST.get('exception')
        name = self.form.name.data.strip()
        email = self.form.email.data.lower()
        message = self.form.message.data.strip()

        try:
            subject = _("Contact")
            # exceptions for error pages that redirect to contact
            if exception != "":
                subject = subject + " (Exception error: %s)" % exception

            template_val = {
                "name":
                name,
                "email":
                email,
                "browser":
                str(httpagentparser.detect(user_agent)['browser']['name']),
                "browser_version":
                str(httpagentparser.detect(user_agent)['browser']['version']),
                "operating_system":
                str(httpagentparser.detect(user_agent)['flavor']['name']) +
                " " +
                str(httpagentparser.detect(user_agent)['flavor']['version']),
                "ip":
                remoteip,
                "message":
                message
            }
            body_path = "emails/contact.txt"
            body = self.jinja2.render_template(body_path, **template_val)

            email_url = self.uri_for('taskqueue-send-email')
            taskqueue.add(url=email_url,
                          params={
                              'to': config.contact_recipient,
                              'subject': subject,
                              'body': body,
                              'sender': config.contact_sender,
                          })

            message = _('Your message was sent successfully.')
            self.add_message(message, 'success')
            return self.redirect_to('contact')

        except (AttributeError, KeyError), e:
            logging.error('Error sending contact form: %s' % e)
            message = _('Error sending the message. Please try again later.')
            self.add_message(message, 'error')
            return self.redirect_to('contact')
Ejemplo n.º 2
0
    def post(self):
        """ validate contact form """

        if not self.form.validate():
            return self.get()
        remoteip  = self.request.remote_addr
        user_agent  = self.request.user_agent
        exception = self.request.POST.get('exception')
        name = self.form.name.data.strip()
        email = self.form.email.data.lower()
        message = self.form.message.data.strip()

        try:
            subject = _("Contact")
            # exceptions for error pages that redirect to contact
            if exception != "":
                subject = subject + " (Exception error: %s)" % exception

            template_val = {
                "name": name,
                "email": email,
                "browser": str(httpagentparser.detect(user_agent)['browser']['name']),
                "browser_version": str(httpagentparser.detect(user_agent)['browser']['version']),
                "operating_system": str(httpagentparser.detect(user_agent)['flavor']['name']) + " " +
                                    str(httpagentparser.detect(user_agent)['flavor']['version']),
                "ip": remoteip,
                "message": message
            }
            body_path = "emails/contact.txt"
            body = self.jinja2.render_template(body_path, **template_val)

            email_url = self.uri_for('taskqueue-send-email')
            taskqueue.add(url = email_url, params={
                'to': config.contact_recipient,
                'subject' : subject,
                'body' : body,
                'sender' : config.contact_sender,
                })

            message = _('Your message was sent successfully.')
            self.add_message(message, 'success')
            return self.redirect_to('contact')

        except (AttributeError, KeyError), e:
            logging.error('Error sending contact form: %s' % e)
            message = _('Error sending the message. Please try again later.')
            self.add_message(message, 'error')
            return self.redirect_to('contact')
Ejemplo n.º 3
0
def before_request():
    """Make sure we are connected to the database each request and look
    up the current user so that we know he's there.
    """
    g.redis = app.redis
    g.user = None
    if request.path.startswith('/static/'):
        return
    ua = httpagentparser.detect(request.user_agent.string)
    g.useragent = ua
    g.using_html5 = False
    if 'dist' in ua and ua['dist'].get('name', '').lower() in ['iphone', 'ipad', 'macintosh'] \
        and 'browser' in ua and ua['browser'].get('name', '').lower() in ['safari']:
        g.using_html5 = True
    if 'user_id' in session:
        g.user = f.load_user(session['user_id'])
    if g.user and 'guide_step' in g.user.extra and not request.path.startswith(
            '/guide/') and not request.path.startswith('/m/'):
        p = None
        if request.referrer:
            parsedurl = urlparse(request.referrer)
            p = parsedurl.path
        if request.path == "/logout/":
            pass
        elif not p or not p.startswith('/guide/'):
            return redirect('/guide/')
Ejemplo n.º 4
0
def before_request():
    """Make sure we are connected to the database each request and look
    up the current user so that we know he's there.
    """
    g.redis = app.redis
    g.user = None
    if request.path.startswith('/static/'):
        return
    ua = httpagentparser.detect(request.user_agent.string)
    g.useragent = ua
    g.using_html5 = False
    if 'dist' in ua and ua['dist'].get('name', '').lower() in ['iphone', 'ipad', 'macintosh'] \
        and 'browser' in ua and ua['browser'].get('name', '').lower() in ['safari']:
        g.using_html5 = True
    if 'user_id' in session:
        g.user = f.load_user(session['user_id'])
    if g.user and 'guide_step' in g.user.extra and not request.path.startswith('/guide/') and not request.path.startswith('/m/'):
        p = None
        if request.referrer:
            parsedurl = urlparse(request.referrer)
            p = parsedurl.path
        if request.path == "/logout/":
            pass
        elif not p or not p.startswith('/guide/'):
            return redirect('/guide/')
Ejemplo n.º 5
0
def _safe_caching_headers():
    """Adds `Origin`_ to the `Vary`_ header to ensure caching works properly.

    Except in IE because it will disable caching completely. The caching
    strategy in that case is out of the scope of this library.
    https://blogs.msdn.microsoft.com/ieinternals/2009/06/17/vary-with-care/
    """
    uah = cherrypy.serving.request.headers.get('User-Agent', '')
    ua = httpagentparser.detect(uah)
    IE = 'Microsoft Internet Explorer'
    if ua.get('browser', {}).get('name') != IE:
        set_vary_header(cherrypy.serving.response, "Origin")
Ejemplo n.º 6
0
def _safe_caching_headers():
    """Adds `Origin`_ to the `Vary`_ header to ensure caching works properly.

    Except in IE because it will disable caching completely. The caching
    strategy in that case is out of the scope of this library.
    https://blogs.msdn.microsoft.com/ieinternals/2009/06/17/vary-with-care/
    """
    uah = cherrypy.serving.request.headers.get('User-Agent', '')
    ua = httpagentparser.detect(uah)
    IE = 'Microsoft Internet Explorer'
    if ua.get('browser', {}).get('name') != IE:
        set_vary_header(cherrypy.serving.response, "Origin")