A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

71 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. """Endpoints for contacting the site owner."""
  3. from flask import Blueprint, request, redirect, url_for, flash
  4. from rophako.utils import template, send_email, remote_addr
  5. from rophako.settings import Config
  6. mod = Blueprint("contact", __name__, url_prefix="/contact")
  7. @mod.route("/")
  8. def index():
  9. return template("contact/index.html")
  10. @mod.route("/send", methods=["POST"])
  11. def send():
  12. """Submitting the contact form."""
  13. name = request.form.get("name", "") or "Anonymous"
  14. email = request.form.get("email", "")
  15. subject = request.form.get("subject", "") or "[No Subject]"
  16. message = request.form.get("message", "")
  17. # Spam traps.
  18. trap1 = request.form.get("contact", "x") != ""
  19. trap2 = request.form.get("website", "x") != "http://"
  20. if trap1 or trap2:
  21. flash("Wanna try that again?")
  22. return redirect(url_for(".index"))
  23. # Message is required.
  24. if len(message) == 0:
  25. flash("The message is required.")
  26. return redirect(url_for(".index"))
  27. # Email looks valid?
  28. reply_to = None
  29. if "@" in email and "." in email:
  30. reply_to = email
  31. # Send the e-mail.
  32. send_email(
  33. to=Config.site.notify_address,
  34. reply_to=reply_to,
  35. subject="Contact Form on {}: {}".format(Config.site.site_name, subject),
  36. message="""A visitor to {site_name} has sent you a message!
  37. IP Address: {ip}
  38. User Agent: {ua}
  39. Referrer: {referer}
  40. Name: {name}
  41. E-mail: {email}
  42. Subject: {subject}
  43. {message}""".format(
  44. site_name=Config.site.site_name,
  45. ip=remote_addr(),
  46. ua=request.user_agent.string,
  47. referer=request.headers.get("Referer", ""),
  48. name=name,
  49. email=email,
  50. subject=subject,
  51. message=message,
  52. )
  53. )
  54. flash("Your message has been delivered.")
  55. return redirect(url_for("index"))