Skip to content

Commit

Permalink
Sanetizando algumas queries
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixoLucas42 committed Apr 27, 2024
1 parent c95f917 commit f68ab8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import timedelta
from flask import Flask, request, jsonify, render_template
import os
import time
import bleach

database_db = 'cardsgo'
database_host = os.getenv('database_host')
Expand Down Expand Up @@ -41,7 +41,7 @@ def delete_expired_cards():
delete = e.fetchall()
for i in delete:
print("Apagando id {} referente ao projeto {} ".format(i[0], i[1]))
e.execute("DELETE FROM cardsgo.cardsgo_data WHERE id_cardsgo='{}'".format(i[0]))
e.execute("DELETE FROM cardsgo.cardsgo_data WHERE id_cardsgo='{}'".format(bleach.clean(i[0])))
conn.commit()
print(e.rowcount, "record(s) deleted")

Expand All @@ -66,7 +66,7 @@ def save_data():
auth_plugin='mysql_native_password'
)
e = conn.cursor()
e.execute("UPDATE cardsgo.cardsgo_data SET expiration = '{}', data = '{}' WHERE (user = '{}');".format(expiration, json.replace('\'', '\\"'), user))
e.execute("UPDATE cardsgo.cardsgo_data SET expiration = '{}', data = '{}' WHERE (user = '{}');".format(bleach.clean(expiration), bleach.clean(json.replace('\'', '\\"')), bleach.clean(user)))
conn.commit()
print(e.rowcount, "record(s) affected")

Expand All @@ -87,11 +87,11 @@ def get_data():
auth_plugin='mysql_native_password'
)
e = conn.cursor()
e.execute("SELECT user FROM cardsgo.cardsgo_data where user = '{}'".format(u))
e.execute("SELECT user FROM cardsgo.cardsgo_data where user = '{}'".format(bleach.clean(u)))
user = e.fetchall()
if (len(user) > 0):
e = conn.cursor()
e.execute("SELECT CONCAT(UNIX_TIMESTAMP(expiration), '000') as expiration, data FROM cardsgo.cardsgo_data where user = '{}';".format(u))
e.execute("SELECT CONCAT(UNIX_TIMESTAMP(expiration), '000') as expiration, data FROM cardsgo.cardsgo_data where user = '{}';".format(bleach.clean(u)))
row_headers=[x[0] for x in e.description]
cards = e.fetchall()
json_data=[]
Expand All @@ -101,10 +101,10 @@ def get_data():
else:
try:
e = conn.cursor()
e.execute("INSERT INTO cardsgo.cardsgo_data (expiration, user, data) VALUES ('{}', '{}', '{}');".format(dt_string, u, raw_cards))
e.execute("INSERT INTO cardsgo.cardsgo_data (expiration, user, data) VALUES ('{}', '{}', '{}');".format(bleach.clean(dt_string), bleach.clean(u), bleach.clean(raw_cards)))
conn.commit()
cards = e.fetchall()
e.execute("SELECT CONCAT(UNIX_TIMESTAMP(expiration), '000') as expiration, data FROM cardsgo.cardsgo_data where user = '{}';".format(u))
e.execute("SELECT CONCAT(UNIX_TIMESTAMP(expiration), '000') as expiration, data FROM cardsgo.cardsgo_data where user = '{}';".format(bleach.clean(u)))
row_headers=[x[0] for x in e.description]
cards = e.fetchall()
json_data=[]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ flask_cors
mysql.connector
flask
mysql-connector-python
flask-cors
flask-cors
bleach

0 comments on commit f68ab8c

Please sign in to comment.