Ejemplo n.º 1
0
    def post(self):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()

        query = "SELECT active FROM tuborg WHERE file_name = '" + args.file_name + "'"

        mycursor.execute(query)
        result = mycursor.fetchone()
        print(result)
        if (result[0] == 0):
            connection.close()

            connection2 = ConnectionHelper.connection()
            mycursor2 = connection2.cursor()

            query = "UPDATE tuborg SET active = 1 where file_name = '" + args.file_name + "'"

            mycursor2.execute(query)

            connection2.commit()

            connection2.close()
            response = {"result": "True"}

            return response
Ejemplo n.º 2
0
    def get(self):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()

        query = "SELECT file_name FROM tuborg WHERE file_id = '" + args.file_id + "'"

        mycursor.execute(query)
        result = mycursor.fetchone()

        response = {"file_name": result[0]}
        connection.close()
        return response
Ejemplo n.º 3
0
    def post(self):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()

        query = "select user_id from user where email = '" + args.email + "' and password = '******'"

        mycursor.execute(query)
        result = mycursor.fetchone()
        connection.close()
        if (result != None):
            return {'user_id' : result[0]}
        else:
            return False
Ejemplo n.º 4
0
    def get(self, user_id):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()

        query = "select sender,file_id from tuborg where file_name = '" + args.file_name + "' and receiver = '" + user_id + "' and active = 1"

        mycursor.execute(query)
        result = mycursor.fetchall()
        connection.close()
        download_link = "http://localhost:6565/file/" + result[0][
            0] + "/" + str(result[0][1])

        response = {"link": download_link}

        return response
Ejemplo n.º 5
0
    def put(self):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()
        date = datetime.datetime.now().isoformat(' ', 'seconds')

        query = "INSERT INTO user (email, password, created_time, last_login) VALUES ('" + args.email + "','" + args.password + "','" + date + "','" + date + "')"

        mycursor.execute(query)

        connection.commit()

        if (mycursor.rowcount != 0):
            connection.close()
            return True
        else:
            connection.close()
            return False
Ejemplo n.º 6
0
    def put(self, user_id):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()

        req_sender = requests.get("http://localhost:1616/userid", data = {"email" : args.sender_email})
        req_receiver = requests.get("http://localhost:1616/userid", data = {"email" : args.receiver_email})

        print(type(req_sender),req_sender.text)
        snd = req_sender.json()
        rcv = req_receiver.json()
        query = "INSERT INTO tuborg (sender,receiver,file_name,active,download_count) VALUES ('{snd['user_id']}','{rcv['user_id']}','{ args.file_name }',0,0)"
        mycursor.execute(query)

        connection.commit()

        if (mycursor.rowcount != 0):
            query = "SELECT file_id FROM tuborg WHERE file_name = '" + args.file_name + "'"

            mycursor.execute(query)
            result = mycursor.fetchone()

            info = {
                "sender_id" : snd['user_id'],
                "receiver_id" : rcv['user_id'],
                "file_id" : result[0]
            }

            connection.close()
            print(info)
            return info
        else:
            info = {
                "sender_id" : "None",
                "receiver_id" : "None",
                "file_id" : "None"
            }
            print("HATA!!!")
            connection.close()
            return info
Ejemplo n.º 7
0
    def post(self, user_id):
        connection = ConnectionHelper.connection()
        mycursor = connection.cursor()
        args = parser.parse_args()

        if (args.email != None and args.password != None):
            query = "UPDATE user SET email = '" + args.email + "',password = '******' where user_id = '" + user_id + "'"
        elif (args.email != None and args.password == None):
            query = "UPDATE user SET email = '" + args.email + "' where user_id = '" + user_id + "'"
        elif (args.email == None and args.password != None):
            query = "UPDATE user SET password = '******' where user_id = '" + user_id + "'"
        else:
            return None

        mycursor.execute(query)

        connection.commit()
        if (mycursor.rowcount != 0):
            connection.close()
            return True
        else:
            connection.close()
            return False