10 changed files with 350 additions and 34 deletions
@ -0,0 +1,67 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
"""Endpoints for contacting the site owner.""" |
|||
|
|||
from flask import Blueprint, g, request, redirect, url_for, session, flash |
|||
import re |
|||
import time |
|||
|
|||
from rophako.utils import template, send_email |
|||
from rophako.log import logger |
|||
from config import * |
|||
|
|||
mod = Blueprint("contact", __name__, url_prefix="/contact") |
|||
|
|||
|
|||
@mod.route("/") |
|||
def index(): |
|||
return template("contact/index.html") |
|||
|
|||
|
|||
@mod.route("/send", methods=["POST"]) |
|||
def send(): |
|||
"""Submitting the contact form.""" |
|||
name = request.form.get("name", "") or "Anonymous" |
|||
email = request.form.get("email", "") |
|||
subject = request.form.get("subject", "") or "[No Subject]" |
|||
message = request.form.get("message", "") |
|||
|
|||
# Spam traps. |
|||
trap1 = request.form.get("contact", "x") != "" |
|||
trap2 = request.form.get("website", "x") != "http://" |
|||
if trap1 or trap2: |
|||
flash("Wanna try that again?") |
|||
return redirect(url_for(".index")) |
|||
|
|||
# Message is required. |
|||
if len(message) == 0: |
|||
flash("The message is required.") |
|||
return redirect(url_for(".index")) |
|||
|
|||
# Send the e-mail. |
|||
send_email( |
|||
to=NOTIFY_ADDRESS, |
|||
subject="Contact Form on {}: {}".format(SITE_NAME, subject), |
|||
message="""A visitor to {site_name} has sent you a message! |
|||
|
|||
IP Address: {ip} |
|||
User Agent: {ua} |
|||
Referrer: {referer} |
|||
Name: {name} |
|||
E-mail: {email} |
|||
Subject: {subject} |
|||
|
|||
{message}""".format( |
|||
site_name=SITE_NAME, |
|||
ip=request.remote_addr, |
|||
ua=request.user_agent.string, |
|||
referer=request.headers.get("Referer", ""), |
|||
name=name, |
|||
email=email, |
|||
subject=subject, |
|||
message=message, |
|||
) |
|||
) |
|||
|
|||
flash("Your message has been delivered.") |
|||
return redirect(url_for("index")) |
@ -0,0 +1,19 @@ |
|||
{% for tag in tags %} |
|||
{% if not tag["small"] %} |
|||
» <a href="{{ url_for('blog.category', category=tag['category']) }}">{{ tag['category'] }}</a> |
|||
<small>({{ tag['count'] }})</small><br> |
|||
{% endif %} |
|||
{% endfor %} |
|||
{% if has_small %} |
|||
<div id="blog_show_more" style="display: none"> |
|||
{% for tag in tags %} |
|||
{% if tag["small"] %} |
|||
» <a href="{{ url_for('blog.category', category=tag['category']) }}">{{ tag['category'] }}</a> |
|||
<small>({{ tag['count'] }})</small><br> |
|||
{% endif %} |
|||
{% endfor %} |
|||
</div> |
|||
<div id="blog_show_less" style="display: block"> |
|||
¤ <a href="#" onClick="$('#blog_show_less').hide(); $('#blog_show_more').show(1000); return false">Show more...</a> |
|||
</div> |
|||
{% endif %} |
@ -0,0 +1,48 @@ |
|||
{% extends "layout.html" %} |
|||
{% block title %}Contact Me{% endblock %} |
|||
{% block content %} |
|||
|
|||
<h1>Contact Me</h1> |
|||
|
|||
You can use the form below to send me an e-mail.<p> |
|||
|
|||
<form name="contact" action="{{ url_for('contact.send') }}" method="POST"> |
|||
<input type="hidden" name="token" value="{{ csrf_token() }}"> |
|||
<table border="0" cellspacing="0" cellpadding="2"> |
|||
<tr> |
|||
<td width="50%" align="left" valign="middle"> |
|||
<strong>Your name:</strong><br> |
|||
<small>(so I know who you are)</small><br> |
|||
<input type="text" size="40" name="name"> |
|||
</td> |
|||
<td width="50%" align="left" valign="middle"> |
|||
<strong>Your email:</strong><br> |
|||
<small>(if you want a response)</small><br> |
|||
<input type="email" size="40" name="email"> |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td colspan="2" align="left" valign="middle"> |
|||
<strong>Message subject:</strong><br> |
|||
<small>(optional)</small><br> |
|||
<input type="text" size="40" name="subject" style="width: 100%"><p> |
|||
|
|||
<strong>Message:</strong><br> |
|||
<small>(required)</small><br> |
|||
<textarea cols="40" rows="12" name="message" style="width: 100%"></textarea> |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td colspan="2" align="right" valign="middle"> |
|||
<button type="submit">Send Message</button> |
|||
</td> |
|||
</tr> |
|||
</table> |
|||
<div style="display: none"> |
|||
If you can see these boxes, don't touch them.<br> |
|||
<input type="text" size="40" name="contact" value=""><br> |
|||
<input type="text" size="40" name="website" value="http://"> |
|||
</div> |
|||
</form> |
|||
|
|||
{% endblock %} |
Loading…
Reference in new issue