Exemple #1
0
def update_user(user_id, data):
    #valid name
    user = nomagic._get_entity_by_id(user_id)
    user_json1 = nomagic._pack(user)
    result = {}

    if "password0" in data and "password1" in data and data[
            "password0"] != data["password1"] and data["password1"] != "":
        #normal update password with old password0 and new password1
        if user["password"] == hashlib.sha1(data["password0"] +
                                            user.get("salt", "")).hexdigest():
            user["password"] = hashlib.sha1(data["password1"] +
                                            user.get("salt", "")).hexdigest()
            result["password_updated"] = True
        del data["password0"]
        del data["password1"]

    elif "password" in data and data["password"] != "":
        #force update password
        user["password"] = hashlib.sha1(data["password"] +
                                        user.get("salt", "")).hexdigest()
        result["password_updated"] = True
        del data["password"]

    if user:
        user.update(data)
        user_json2 = nomagic._pack(user)
        if user_json1 != user_json2:
            assert nomagic._node(user_id).execute_rowcount(
                "UPDATE entities SET body = %s WHERE id = %s",
                nomagic._pack(user), nomagic._key(user_id))
            BIG_CACHE.unset(user_id)
    return result
Exemple #2
0
def update_user(user_id, data):
    #valid name
    user = nomagic._get_entity_by_id(user_id)
    user_json1 = nomagic._pack(user)
    if user:
        user.update(data)
        user_json2 = nomagic._pack(user)
        if user_json1 != user_json2:
            assert ring[nomagic._number(user_id)].execute_rowcount(
                "UPDATE entities SET body = %s WHERE id = %s",
                nomagic._pack(user), nomagic._key(user_id))
Exemple #3
0
def update_user(user_id, data):
    #valid name
    user = nomagic._get_entity_by_id(user_id)
    user_json1 = nomagic._pack(user)
    result = {}

    if "password0" in data and "password1" in data and data["password0"] != data["password1"] and data["password1"]:
        #normal update password with old password0 and new password1
        if user["password"] == hashlib.sha1(data["password0"] + user.get("salt", "")).hexdigest():
            user["password"] = hashlib.sha1(data["password1"] + user.get("salt", "")).hexdigest()
            result["password_updated"] = True
        del data["password0"]
        del data["password1"]

    if user:
        user.update(data)
        user_json2 = nomagic._pack(user)
        if user_json1 != user_json2:
            assert nomagic._node(user_id).execute_rowcount("UPDATE entities SET body = %s WHERE id = %s", nomagic._pack(user), nomagic._key(user_id))
    return result
Exemple #4
0
def update_chat(chat_id, data):
    rowcount = nomagic._node(chat_id).execute_rowcount(
        "UPDATE entities SET body = %s WHERE id = %s", nomagic._pack(data),
        nomagic._key(chat_id))
    assert rowcount
Exemple #5
0
def update_user(user_id, data):
    #valid name
    user = nomagic._get_entity_by_id(user_id)
    user_json1 = nomagic._pack(user)
    if user:
        user.update(data)
        user_json2 = nomagic._pack(user)
        if user_json1 != user_json2:
            assert ring[nomagic._number(user_id)].execute_rowcount("UPDATE entities SET body = %s WHERE id = %s", nomagic._pack(user), nomagic._key(user_id))