Exemple #1
0
    dispacher = Dispacher()

    salt = generate_salt()
    connection = create_connection()
    cursor = get_cursor(connection)

    option_handler = OptionsHandler(args.password, args.username,
                                    args.new_password, args.edit, args.delete,
                                    args.list, args.send, args.to)

    if option_handler.create_user:
        print(dispacher.create_user(args.username, args.password))
    elif option_handler.list_all_users:
        print(dispacher.print_all_users())
    elif option_handler.list_all_messages_for_user:
        print(dispacher.list_messages_to_user(args.username, args.password))
    elif option_handler.change_password:
        print(
            dispacher.change_password(args.username, args.password,
                                      args.new_password))
    elif option_handler.send_message:
        print(
            dispacher.send_message(args.username, args.password, args.to,
                                   args.send))
    elif option_handler.delete_user:
        print(dispacher.delete_user(args.username, args.password))
    else:
        dispacher.not_available_option()

    cursor.close()
    connection.close()
Exemple #2
0
                                    args.list, args.send, args.to)

    if option_handler.create_user:
        result = dispacher.login_user(args.username, args.password)
        if result[1] == 1:
            dispacher.create_user(args.username, args.password)
            print('User {} created'.format(args.username))

    elif option_handler.list_all_users:
        if dispacher.all_users_list():
            print('All users list')

    elif option_handler.list_all_messages_for_user:
        result = dispacher.login_user(args.username, args.password)
        if isinstance(result[0], User):
            dispacher.list_messages_to_user(result[0])

    elif option_handler.change_password:
        result = dispacher.login_user(args.username, args.password)
        if isinstance(result[0], User):
            dispacher.change_password(result[0], args.new_password)
            print('Password Changed!')
        else:
            print('Password change failed!')

    elif option_handler.send_message:
        result = dispacher.login_user(args.username, args.password)
        if isinstance(result[0], User):
            if dispacher.send_message(args.to, result[0].email, args.send):
                print('Message send from user {} to user {}'.format(
                    result[0].email, args.to))