Example #1
0
def import_(who, user):
    soup = BeautifulSoup(request.body)
    if soup.contents[0] != "NETSCAPE-Bookmark-file-1":
        abort(400, "You must send a bookmark file with the doctype " +
              " 'NETSCAPE-Bookmarks-file-1'")
    anchors = soup.find_all("a")
    bookmarks = []
    add_dates = set()
    for anchor in anchors:
        bookmark = {
            "~": int(anchor.attrs.get("add_date", conv.unixtime()))
            }
        while bookmark["~"] in add_dates:
            bookmark["~"] += 1
        add_dates.add(bookmark["~"])
        bookmark["hyperlink"] = anchor.attrs["href"]
        if bookmark["hyperlink"].startswith("place"):
            continue
        bookmark["title"] = anchor.string
        bookmark["@"] = user["email"]
        bookmark["%private"] = True
        bookmark["£created"] = conv.unixtime()
        bookmarks.append(bookmark)
    for each in bookmarks:
        conv.db().eachs.insert(each)
        del each["_id"]
        jobs.enqueue(search.IndexRecord(each), priority=1)
    response.status = 202
Example #2
0
def add_public(who, when, user):
    if "~" not in request.json or "@" not in request.json:
        abort(400, "You must include @ and ~ with all bookmarks")
    if request.json["@"] != who or who != user["email"]:
        abort(400, "You may only add bookmarks as yourself")
    if request.json["~"] != int(when):
        abort(400, "You must use the same time in the bookmark as you post to")
    if data.has_problematic_keys(request.json):
        abort(400, "Bookmarks must not have keys prefixed with $ or £")
    request.json["£created"] = conv.unixtime()
    conv.db().bookmarks.insert(request.json)
    del request.json["_id"]
    jobs.enqueue(search.IndexRecord(request.json), priority=1)
    response.status = 202
Example #3
0
def request_invite(who):
    # FIXME: Don't allow the pseudonym "public"
    user = whitelist(request.json, [
            "pseudonym",
            "firstName",
            "surname",
            "private_email",
            "token",
            ])
    if "private_email" not in user:
        abort(400, "You must provide a private_email field")
    user["email_key"] = str(uuid.uuid4())
    user["registered"] = c.unixtime()
    user["email"] = who
    c.db().users.ensure_index("email", unique=True)
    c.db().users.insert(user, safe=True)
    response.status = 202
    logger.info("{email} subscribed".format(email=who))
    jobs.enqueue(messages.SendInvite(user))
Example #4
0
def verify_email(who, email_key):
    if "RECALL_TEST_MODE" in c.settings or "RECALL_DEBUG_MODE" in c.settings:
        salt = bcrypt.gensalt(1)
    else:
        salt = bcrypt.gensalt()
    password_hash = bcrypt.hashpw(request.json["password"], salt)

    spec = {"email_key": email_key, "verified": {"$exists": False}}
    update = {"$set": {"password_hash": password_hash,
                       "verified": c.unixtime()}}
    success = c.db().users.update(spec, update, safe=True)["updatedExisting"]
    if not success:
        if c.db().users.find_one({"email_key": email_key}):
            logger.warn("{email} tried to verify a second time".format(email=who))
            abort(403, "Already verified")
        else:
            logger.warn("Someone tried to verify with a key, but it doesn't exist")
            abort(404, "Don't know that key")
    user = c.db().users.find_one({"email_key": email_key})
    response.status = 201
    return blacklist(user, ["_id", "email_key",  "password_hash"])