Exemplo n.º 1
0
 def find_by_recipient(cursor, recipient_username):
     sql = "SELECT id, from_user, to_user, context, created_at FROM messages WHERE to_user=%s"
     ret = []
     cursor.execute(sql, (recipient_username, ))
     for row in cursor.fetchall():
         loaded_message = Message()
         loaded_message._id = row[0]
         loaded_message.from_user = row[1]
         loaded_message.to_user = row[2]
         loaded_message.context = row[3]
         loaded_message.created_at = row[4]
         ret.append(loaded_message)
     return ret
Exemplo n.º 2
0
 def load_all_msg(cursor):
     sql = "SELECT * FROM messages"
     ret = []
     cursor.execute(sql)
     for row in cursor.fetchall():
         loaded_msg = Message()
         loaded_msg._id = row[0]
         from_user_temp = UserService.find_by_id(cursor, row[1])
         loaded_msg.from_user = from_user_temp.username
         to_user_temp = UserService.find_by_id(cursor, row[2])
         loaded_msg.to_user = to_user_temp.username
         loaded_msg.context = row[3]
         loaded_msg.created_at = row[4]
         ret.append(loaded_msg)
     return ret
Exemplo n.º 3
0
 def find_by_recipient(cursor, recipient_username):
     sql = "SELECT id, from_user, to_user, context, created_at FROM messages WHERE to_user=%s"
     ret = []
     cursor.execute(sql, (recipient_username, ))
     data = cursor.fetchall()
     if data:
         for row in data:
             loaded_msg = Message()
             loaded_msg._id = row[0]
             from_user_temp = UserService.find_by_id(cursor, row[1])
             loaded_msg.from_user = from_user_temp.username
             to_user_temp = UserService.find_by_id(cursor, row[2])
             loaded_msg.to_user = to_user_temp.username
             loaded_msg.context = row[3]
             loaded_msg.created_at = row[4]
             ret.append(loaded_msg)
         return ret
     else:
         return None
Exemplo n.º 4
0
        user = MessageService.find_by_recipient(cursor, args.username)
    print('Wrong data provided')

    if args.send == True:
        user = UserService.find_by_username(cursor, args.username)
        if user is not None:
            is_user_logged = UserService.login(cursor, args.username,
                                               args.password)
            if is_user_logged == True:
                to_user = UserService.find_by_username(cursor, args.username)
                if to_user is not None:
                    context = args.message
                    if context:
                        message = Message()
                        message.from_user = user.id
                        message.to_user = to_user.id
                        message.context = args.message
                        message.created_at = datetime.now()
                        message.save(cursor)
                        print("Message successfully sent")
                    else:
                        print("Message is empty!")
                else:
                    print("Wrong username")
            else:
                print('Please login')
        else:
            print('Invalid username or password')

    cursor.close()
    connection.close()
Exemplo n.º 5
0
        else:
            print('Username or password invalid')

    if args.send == True:
        user = UserService.find_by_username(cursor, args.username)
        if user is not None:
            is_user_logged = UserService.login(cursor, args.username, args.password)
            if is_user_logged == True:
                to_user = UserService.find_by_email(cursor, args.email)
                if to_user is not None:
                    context = args.message
                    if context:
                        msg = Message()
                        msg.from_user = user.id
                        msg.to_user = to_user.id
                        msg.context = args.message
                        msg.created_at = datetime.now()
                        msg.save(cursor)
                        print("Message send")
                    else:
                        print("No message provided")
                else:
                    print("No user with that email")

            else:
                print('Username or password invalid')
        else:
            print('Username or password invalid')

    cursor.close()
    connection.close()