示例#1
0
def publishmaze(id, user):
    r = web.ctx.db.where("mazes", id=id)
    try:
        row = r[0]
    except IndexError:
        return {"error": "INCORRECT_MAZE_ID"}
    if row.owner != user:
        return {"error": "USER_DOES_NOT_OWN_MAZE"}
    r = web.ctx.db.where("published_mazes", data=row.data)
    for dup in r:
        return {"error": "DUPLICATE_MAZE"}
    id = web.ctx.db.insert("published_mazes",
                      title=row.title,
                      description=row.description,
                      owner=user,
                      date=datetime.datetime.now(),
                      data=row.data)
    if web.ctx.session.user_email:
        body = """
Thank you for submitting your maze entitled '%s' for publication.
It is now awaiting moderation.  You will be notified as soon as a moderator
has taken a decision about it.
""" % row.title
        subject = "Maze submission: " + row.title
        mail = Mail(user, web.ctx.session.user_email, subject, body)
        mail.send()
    return {id: id}
示例#2
0
def moderate(user, mazeid, decision, comment):
    if not web.ctx.session.moderator:
        return {"error": "USER_MUST_BE_MODERATOR"}
    r = web.ctx.db.where("published_mazes", id=mazeid)
    # Return error if maze has already been moderated or removed
    for row in r:
        if row.moderated_by is None:
            break
    else:
        return {"error": "MAZE_ALREADY_MODERATED"}
    r = web.ctx.db.where("users", username=row.owner)
    for owner in r:
        pass
    maze_info = dict(row)
    if decision == "ACCEPT":
        r = web.ctx.db.update("published_mazes",
                vars={"id": mazeid},
                where="id=$id",
                moderated_by=web.ctx.session.username)
    elif decision == "REJECT" or decision == "IMPROVE":
        r = web.ctx.db.delete("published_mazes", 
                              vars={"id": mazeid},
                              where="id=$id")
    if not r:
        return {"error": "MAZE_ALREADY_MODERATED"}
    if owner.email:
        subject = "Maze moderation: %s" % row.title
        decision_string = {
            "ACCEPT": "Congratulations, it has been accepted for publication!",
            "REJECT": "The moderator decided not to accept it for publication.",
            "IMPROVE": "The moderator thinks that some changes are needed before it can be published."
            }
        body = """
Your maze has been moderated by %s.  %s

The moderator left this comment:
----
%s
----
""" % (user, decision_string[decision], comment)
        mail = Mail(owner.username, owner.email, subject, body)
        mail.send()
    return {"status": decision}
示例#3
0
def setemail(user, email):
    # Create a randomish token
    token = hashlib.md5(str(time.time())).hexdigest()
    web.ctx.db.insert("email_tokens",
                   token=token,
                   user=user,
                   email=email)
    token_addr = web.ctx.home + "/confirm/?token=" + token
    subject = "Request to link email to account"
    body = """
It appears you have requested to link your robot2flags account
to this email address (%s).

To confirm, follow this link:

    %s

You can safely ignore this message if you have not made this request
or if you are not %s.
""" % (email, token_addr, user)
    mail = Mail(user, email, subject, body)
    mail.send()
    return {"status": "OK"}