def validate_user(user_tok): toConfirmId = decode_uid(user_tok) if toConfirmId is None or not uid_exists(toConfirmId): return render_template("register_validate.html", valid=False) else: get_db().users.update({"_id": toConfirmId}, {"$set": { "confirmed": "true" }}) user = get_db().users.find_one({"_id": toConfirmId}) return render_template("register_validate.html", valid=True, name=user["first_name"] + " " + user["last_name"], email=user["email_address"])
def user_exists(email_to_check): found = get_db().users.find({"email_address": email_to_check}).limit(1) if found.count() == 0: return False, False else: u = found.next() return (u["_id"], u["confirmed"])
def create_user(user_document): # TODO check for re-used email... lastID = get_db().users.find({}, {"_id": 1}).sort("_id", -1).limit(1) # Special case for the very first user. if lastID.count() == 0: # Set to 0 so first ID is 1 lastID = 0 else: lastID = lastID.next()["_id"] doc = user_document.copy() newID = str(int(lastID) + 1) doc["_id"] = newID doc["confirmed"] = False doc["role"] = "user" get_db().users.insert(doc) return newID
def is_confirmed_uid(uid): return get_db().users.find({"_id": uid}).limit(1).next()["confirmed"]
def uid_exists(uid): return get_db().users.find({"_id": uid}).limit(1).count() == 1