diff --git a/Pipfile b/Pipfile index f1e49972..649f7eb8 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,7 @@ SQLAlchemy = "*" itsdangerous = "*" authlib = "*" httpx = "*" +psycopg2 = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index a309eb0a..a45eacdc 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6ca6b02d3e09088dc3222522eca7541395222607b1972f986791dcb3bf1259aa" + "sha256": "0e2f744e18603585f1999ed3b99d09c11bd0cfff59618c506edb2dad1c91314e" }, "pipfile-spec": 6, "requires": { @@ -295,6 +295,21 @@ "index": "pypi", "version": "==1.7.4" }, + "psycopg2": { + "hashes": [ + "sha256:079d97fc22de90da1d370c90583659a9f9a6ee4007355f5825e5f1c70dffc1fa", + "sha256:2087013c159a73e09713294a44d0c8008204d06326006b7f652bef5ace66eebb", + "sha256:2c992196719fadda59f72d44603ee1a2fdcc67de097eea38d41c7ad9ad246e62", + "sha256:7640e1e4d72444ef012e275e7b53204d7fab341fb22bc76057ede22fe6860b25", + "sha256:7f91312f065df517187134cce8e395ab37f5b601a42446bdc0f0d51773621854", + "sha256:830c8e8dddab6b6716a4bf73a09910c7954a92f40cf1d1e702fb93c8a919cc56", + "sha256:89409d369f4882c47f7ea20c42c5046879ce22c1e4ea20ef3b00a4dfc0a7f188", + "sha256:bf35a25f1aaa8a3781195595577fcbb59934856ee46b4f252f56ad12b8043bcf", + "sha256:de5303a6f1d0a7a34b9d40e4d3bef684ccc44a49bbe3eb85e3c0bffb4a131b7c" + ], + "index": "pypi", + "version": "==2.9.1" + }, "pycparser": { "hashes": [ "sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0", diff --git a/auth/token.py b/auth/token.py index d3fa5715..74b9b38e 100644 --- a/auth/token.py +++ b/auth/token.py @@ -10,7 +10,7 @@ class Token: @staticmethod def encode(user: User, exp: datetime, device: str = "pc") -> str: payload = {"user_id": user.id, "device": device, "exp": exp, "iat": datetime.utcnow()} - return jwt.encode(payload, JWT_SECRET_KEY, JWT_ALGORITHM).decode("UTF-8") + return jwt.encode(payload, JWT_SECRET_KEY, JWT_ALGORITHM) @staticmethod def decode(token: str, verify_exp: bool = True) -> PayLoad: diff --git a/orm/base.py b/orm/base.py index cf5ec589..e3c89c6d 100644 --- a/orm/base.py +++ b/orm/base.py @@ -5,9 +5,9 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy.sql.schema import Table -from settings import SQLITE_URI +from settings import DB_URI -engine = create_engine(f'sqlite:///{SQLITE_URI}', convert_unicode=True, echo=False) +engine = create_engine(DB_URI, convert_unicode=True, echo=False) Session = sessionmaker(autocommit=False, autoflush=False, bind=engine) global_session = Session() diff --git a/settings.py b/settings.py index 911f9ace..1cb3a9a0 100644 --- a/settings.py +++ b/settings.py @@ -3,7 +3,7 @@ from os import environ PORT = 80 -SQLITE_URI = Path(__file__).parent / "database.sqlite3" +DB_URI = environ.get("DB_URI") or "postgresql://postgres:postgres@localhost/discours" JWT_ALGORITHM = "HS256" JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key" JWT_LIFE_SPAN = 24 * 60 * 60 # seconds