示例#1
0
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"))

    # Email looks valid?
    reply_to = None
    if "@" in email and "." in email:
        reply_to = email

    # Send the e-mail.
    send_email(
        to=Config.site.notify_address,
        reply_to=reply_to,
        subject="Contact Form on {}: {}".format(Config.site.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=Config.site.site_name,
            ip=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"))
示例#2
0
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"))

    # Email looks valid?
    reply_to = None
    if "@" in email and "." in email:
        reply_to = email

    # Send the e-mail.
    send_email(to=Config.site.notify_address,
               reply_to=reply_to,
               subject="Contact Form on {}: {}".format(Config.site.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=Config.site.site_name,
                   ip=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"))
示例#3
0
文件: comment.py 项目: kirsle/rophako
def add_comment(thread, uid, name, subject, message, url, time, ip,
    token=None, image=None):
    """Add a comment to a comment thread.

    Parameters:
        thread (str): the unique comment thread name.
        uid (int): 0 for guest posts, otherwise the UID of the logged-in user.
        name (str): the commenter's name (if a guest)
        subject (str)
        message (str)
        url (str): the URL where the comment can be read (i.e. the blog post)
        time (int): epoch time of the comment.
        ip (str): the user's IP address.
        token (str): the user's session's comment deletion token.
        image (str): the URL to a Gravatar image, if any.
    """

    # Get the comments for this thread.
    comments = get_comments(thread)

    # Make up a unique ID for the comment.
    cid = random_hash()
    while cid in comments:
        cid = random_hash()

    # Add the comment.
    comments[cid] = dict(
        uid=uid,
        name=name or "Anonymous",
        image=image or "",
        message=message,
        time=time or int(time.time()),
        ip=ip,
        token=token,
    )
    write_comments(thread, comments)

    # Get info about the commenter.
    if uid > 0:
        user = User.get_user(uid=uid)
        if user:
            name = user["name"]

    # Send the e-mail to the site admins.
    send_email(
        to=Config.site.notify_address,
        subject="Comment Added: {}".format(subject),
        message="""{name} has left a comment on: {subject}

{message}

-----

To view this comment, please go to <{url}>

Was this comment spam? [Delete it]({deletion_link}).""".format(
            name=name,
            subject=subject,
            message=message,
            url=url,
            deletion_link=url_for("comment.quick_delete",
                token=make_quick_delete_token(thread, cid),
                url=url,
                _external=True,
            )
        ),
    )

    # Notify any subscribers.
    subs = get_subscribers(thread)
    for sub in subs.keys():
        # Make the unsubscribe link.
        unsub = url_for("comment.unsubscribe", thread=thread, who=sub, _external=True)

        send_email(
            to=sub,
            subject="New Comment: {}".format(subject),
            message="""Hello,

{name} has left a comment on: {subject}

{message}

-----

To view this comment, please go to <{url}>""".format(
                thread=thread,
                name=name,
                subject=subject,
                message=message,
                url=url,
                unsub=unsub,
            ),
            footer="You received this e-mail because you subscribed to the "
                "comment thread that this comment was added to. You may "
                "[**unsubscribe**]({unsub}) if you like.".format(
                unsub=unsub,
            ),
        )
示例#4
0
def add_comment(thread,
                uid,
                name,
                subject,
                message,
                url,
                time,
                ip,
                image=None):
    """Add a comment to a comment thread.

    * uid is 0 if it's a guest post, otherwise the UID of the user.
    * name is the commenter's name (if a guest)
    * subject is for the e-mails that are sent out
    * message is self explanatory.
    * url is the URL where the comment can be read.
    * time, epoch time of comment.
    * ip is the IP address of the commenter.
    * image is a Gravatar image URL etc.
    """

    # Get the comments for this thread.
    comments = get_comments(thread)

    # Make up a unique ID for the comment.
    cid = random_hash()
    while cid in comments:
        cid = random_hash()

    # Add the comment.
    comments[cid] = dict(
        uid=uid,
        name=name or "Anonymous",
        image=image or "",
        message=message,
        time=time or int(time.time()),
        ip=ip,
    )
    write_comments(thread, comments)

    # Get info about the commenter.
    if uid > 0:
        user = User.get_user(uid=uid)
        if user:
            name = user["name"]

    # Send the e-mail to the site admins.
    send_email(
        to=Config.site.notify_address,
        subject="New comment: {}".format(subject),
        message="""{name} has left a comment on: {subject}

{message}

To view this comment, please go to {url}

=====================

This e-mail was automatically generated. Do not reply to it.""".format(
            name=name,
            subject=subject,
            message=message,
            url=url,
        ),
    )

    # Notify any subscribers.
    subs = get_subscribers(thread)
    for sub in subs.keys():
        # Make the unsubscribe link.
        unsub = url_for("comment.unsubscribe",
                        thread=thread,
                        who=sub,
                        _external=True)

        send_email(to=sub,
                   subject="New Comment: {}".format(subject),
                   message="""Hello,

You are currently subscribed to the comment thread '{thread}', and somebody has
just added a new comment!

{name} has left a comment on: {subject}

{message}

To view this comment, please go to {url}

=====================

This e-mail was automatically generated. Do not reply to it.

If you wish to unsubscribe from this comment thread, please visit the following
URL: {unsub}""".format(
                       thread=thread,
                       name=name,
                       subject=subject,
                       message=message,
                       url=url,
                       unsub=unsub,
                   ))
示例#5
0
文件: comment.py 项目: TeMbl4/rophako
def add_comment(thread, uid, name, subject, message, url, time, ip, image=None):
    """Add a comment to a comment thread.

    * uid is 0 if it's a guest post, otherwise the UID of the user.
    * name is the commenter's name (if a guest)
    * subject is for the e-mails that are sent out
    * message is self explanatory.
    * url is the URL where the comment can be read.
    * time, epoch time of comment.
    * ip is the IP address of the commenter.
    * image is a Gravatar image URL etc.
    """

    # Get the comments for this thread.
    comments = get_comments(thread)

    # Make up a unique ID for the comment.
    cid = random_hash()
    while cid in comments:
        cid = random_hash()

    # Add the comment.
    comments[cid] = dict(
        uid=uid,
        name=name or "Anonymous",
        image=image or "",
        message=message,
        time=time or int(time.time()),
        ip=ip,
    )
    write_comments(thread, comments)

    # Get info about the commenter.
    if uid > 0:
        user = User.get_user(uid=uid)
        if user:
            name = user["name"]

    # Send the e-mail to the site admins.
    send_email(
        to=Config.site.notify_address,
        subject="New comment: {}".format(subject),
        message="""{name} has left a comment on: {subject}

{message}

To view this comment, please go to {url}

=====================

This e-mail was automatically generated. Do not reply to it.""".format(
            name=name,
            subject=subject,
            message=message,
            url=url,
        ),
    )

    # Notify any subscribers.
    subs = get_subscribers(thread)
    for sub in subs.keys():
        # Make the unsubscribe link.
        unsub = url_for("comment.unsubscribe", thread=thread, who=sub, _external=True)

        send_email(
            to=sub,
            subject="New Comment: {}".format(subject),
            message="""Hello,

You are currently subscribed to the comment thread '{thread}', and somebody has
just added a new comment!

{name} has left a comment on: {subject}

{message}

To view this comment, please go to {url}

=====================

This e-mail was automatically generated. Do not reply to it.

If you wish to unsubscribe from this comment thread, please visit the following
URL: {unsub}""".format(
                thread=thread,
                name=name,
                subject=subject,
                message=message,
                url=url,
                unsub=unsub,
            )
        )