Пример #1
0
def get_sent_messages(id):
    if is_valid_id(id):
        messages = []

        fileReader = FileReader(path_to_file)
        for json_mess in fileReader.get_json():
            message_id = json_mess["_id"]
            if not is_valid_id(message_id) or not is_valid_id(
                    json_mess["receiver"]) or not is_valid_id(
                        json_mess["sender"]):
                raise IDException

            if json_mess["sender"] == id:
                # TODO dit is niet goed!!! gebruikt wachtwoord dat niet van deze persoon is!!!
                # print("!!! TODO Gebruikt paswoord dan niet van deze persoon is !!! \n Hoe lossen we dit op!?!?!?!")
                pub_sender = get_pub_key(id)
                priv_receiver = get_priv_key(
                    json_mess["receiver"],
                    get_user_pass_hash(json_mess["receiver"]))
                messages.append(
                    decrypt_full_message(json_mess, pub_sender,
                                         priv_receiver).as_dict())
        return jsonify(messages)
    else:
        raise IDException()
def get_salt(username: str):
    fileReader = FileReader(path_to_file)
    for user_attributes in fileReader.read_words_by_line(","):
        username_db = user_attributes[1]
        if username_db == username:
            if user_attributes[6][-1] == '\n':
                return jsonify(user_attributes[6][:-1])
            return jsonify(user_attributes[6])
def check_username(username):
    fileReader = FileReader(path_to_file)
    for user_attributes in fileReader.read_words_by_line(","):
        if not is_valid_id(user_attributes[0]):
            raise IDException
        if username == user_attributes[1]:
            return "false"
    return "true"
def get_list_of_users():
    users = []
    fileReader = FileReader(path_to_file)
    for user_attributes in fileReader.read_words_by_line(","):
        if not is_valid_id(user_attributes[0]):
            raise IDException
        users.append(
            User(user_attributes[0], user_attributes[1], user_attributes[2],
                 user_attributes[3], user_attributes[4], user_attributes[5]))
    return users
def get_all_users():
    users = []
    fileReader = FileReader(path_to_file)
    for user_attributes in fileReader.read_words_by_line(","):
        if not is_valid_id(user_attributes[0]):
            raise IDException
        users.append(
            User(user_attributes[0], user_attributes[1], user_attributes[2],
                 user_attributes[3], user_attributes[4]).as_dict())
    return jsonify(users)
def get_user_pass_hash(id: str):
    fileReader = FileReader(path_to_file)
    for user_attributes in fileReader.read_words_by_line(","):
        user_id = user_attributes[0]
        if not is_valid_id(user_id):
            raise IDException

        if user_id == id:
            return user_attributes[5]

    else:
        raise IDException()
Пример #7
0
def get_all_messages():
    messages = []
    fileReader = FileReader(path_to_file)
    for message_attributes in fileReader.read_words_by_line(","):
        if not is_valid_id(message_attributes[0]):
            raise IDException
        messages.append(
            Message(message_attributes[0], message_attributes[1],
                    message_attributes[2], message_attributes[3],
                    message_attributes[4], message_attributes[5],
                    message_attributes[5],
                    (message_attributes[6], message_attributes[7])).as_dict())
    return jsonify(messages)
Пример #8
0
    def get(id: str):
        if is_valid_id(id):

            fileReader = FileReader(path_to_file)
            for user_attributes in fileReader.read_words_by_line(","):
                user_id = user_attributes[0]
                if not is_valid_id(user_id):
                    raise IDException

                if user_id == id:
                    return User(user_attributes[0], user_attributes[1],
                                user_attributes[2], user_attributes[3],
                                user_attributes[4], user_attributes[5])

        else:
            raise IDException()
Пример #9
0
def get_message(id):
    if is_valid_id(id):

        fileReader = FileReader(path_to_file)
        for message_attributes in fileReader.read_words_by_line(","):
            message_id = message_attributes[0]
            if not is_valid_id(message_id):
                raise IDException

            if message_id == id:
                return jsonify(
                    Message(message_attributes[0], message_attributes[1],
                            message_attributes[2], message_attributes[3],
                            message_attributes[4], message_attributes[5],
                            message_attributes[5],
                            (message_attributes[6],
                             message_attributes[7])).as_dict())

    else:
        raise IDException()
Пример #10
0
def get_my_messages(id):
    messages = []

    if is_valid_id(id):
        fileReader = FileReader(path_to_file)
        for json_mess in fileReader.get_json():
            if not is_valid_id(json_mess["_id"]) or not is_valid_id(
                    json_mess["receiver"]) or not is_valid_id(
                        json_mess["sender"]):
                raise IDException

            if json_mess["receiver"] == id:
                pub_sender = get_pub_key(json_mess["sender"])
                priv_receiver = get_priv_key(
                    json_mess["receiver"],
                    get_user_pass_hash(json_mess["receiver"]))
                messages.append(
                    decrypt_full_message(json_mess, pub_sender,
                                         priv_receiver).as_dict())
        return jsonify(messages)
    else:
        raise IDException()
Пример #11
0
def get_idea(id):
    file_reader = FileReader(path_to_files + id + ".txt")
    return file_reader.get_json()