add env file support
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
JWT_SECRET=your_jwt_secret_key_here
|
||||||
|
JWT_ALGORITHM=HS256
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
.venv
|
.venv
|
||||||
database.db
|
database.db
|
||||||
|
.env
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
fastapi[standard]==0.121.2
|
fastapi[standard]==0.121.2
|
||||||
passlib==1.7.4
|
passlib==1.7.4
|
||||||
pyjwt==2.10.1
|
pyjwt==2.10.1
|
||||||
|
pydantic-settings==2.12.0
|
||||||
|
|||||||
9
settings.py
Normal file
9
settings.py
Normal 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()
|
||||||
Reference in New Issue
Block a user