feat: moved queries to database module
This commit is contained in:
parent
8bbda345bb
commit
54d8ad46f8
16
ajusta_bling/database/queries/auth.py
Normal file
16
ajusta_bling/database/queries/auth.py
Normal 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,
|
||||||
|
)
|
||||||
|
)
|
|
@ -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("/")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user