feat: moved queries to database module

This commit is contained in:
ka 2024-06-15 14:11:05 -03:00
parent 8bbda345bb
commit 54d8ad46f8
Signed by: ka
GPG Key ID: 77D32BB1496F3FD1
2 changed files with 19 additions and 27 deletions

View File

@ -0,0 +1,16 @@
import psycopg2.extensions
def insert_token(cur: psycopg2.extensions.cursor, ip_address: str, access_token: str, refresh_token: str, expires_in: str):
cur.execute(
"""
INSERT INTO auth.tokens
(ip_address,access_token,refresh_token,expires_in) VALUES (%s,%s,%s,%s)
""",
(
ip_address, # ip
access_token,
refresh_token,
expires_in,
)
)

View File

@ -7,6 +7,7 @@ from os import getenv
import requests import requests
from flask import Flask, redirect, request, session, url_for from flask import Flask, redirect, request, session, url_for
import ajusta_bling.database.queries.auth as sqlAuth
from ajusta_bling.common import Args from ajusta_bling.common import Args
from ajusta_bling.database import Database from ajusta_bling.database import Database
@ -44,38 +45,13 @@ def callback():
data = payload, data = payload,
headers= {"Authorization": header}) headers= {"Authorization": header})
data = response.json() data = response.json()
print(response.url)
print(data)
access_token: str = str(data["access_token"]) access_token: str = str(data["access_token"])
refresh_token: str = str(data["refresh_token"]) refresh_token: str = str(data["refresh_token"])
expires_in: int = int(data["expires_in"]) expires_in: int = int(data["expires_in"])
with db.get_cur() as cur: # TODO with db.get_cur() as cur:
cur.execute( sqlAuth.insert_token(cur, request.remote_addr, access_token, refresh_token, expires_in)
"""
INSERT INTO auth.tokens
(
ip_address,
access_token,
refresh_token,
expires_in
) VALUES (
%s,
%s,
%s,
%s
)
""",
(
request.remote_addr, # ip
access_token,
refresh_token,
str(expires_in),
)
)
#TODO: Store the session in the database
#insert_session(payload['access_token'], payload['refresh_token'], payload['expires_in'])
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route("/") @app.route("/")