Compare commits

..

2 Commits

Author SHA1 Message Date
eeea1b2091 add env file support 2025-11-16 14:38:23 +01:00
129e1984a3 add requirements.txt 2025-11-16 14:33:33 +01:00
5 changed files with 19 additions and 4 deletions

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
JWT_SECRET=your_jwt_secret_key_here
JWT_ALGORITHM=HS256

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
__pycache__ __pycache__
.venv .venv
database.db database.db
.env

View File

@@ -1,11 +1,10 @@
from models import User from models import User
from passlib.context import CryptContext from passlib.context import CryptContext
from settings import settings
import sqlite3 import sqlite3
import jwt import jwt
import datetime import datetime
JWT_SECRET = "secret"
connection = sqlite3.connect('database.db') connection = sqlite3.connect('database.db')
connection.row_factory = sqlite3.Row connection.row_factory = sqlite3.Row
cursor = connection.cursor() cursor = connection.cursor()
@@ -46,4 +45,4 @@ def login(user: User) -> str:
"exp": exp "exp": exp
} }
return jwt.encode(payload=payload, key=JWT_SECRET, algorithm="HS256") return jwt.encode(payload=payload, key=settings.jwt_secret, algorithm=settings.jwt_algorithm)

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
fastapi[standard]==0.121.2
passlib==1.7.4
pyjwt==2.10.1
pydantic-settings==2.12.0

9
settings.py Normal file
View File

@@ -0,0 +1,9 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
jwt_secret: str
jwt_algorithm: str
settings = Settings()