feat: features for bad internet connections
This commit is contained in:
parent
1a1b44743a
commit
8e91724462
2
db.py
2
db.py
@ -12,7 +12,7 @@ from sqlmodel import (
|
|||||||
with open("db.secrets", "r") as f:
|
with open("db.secrets", "r") as f:
|
||||||
db_secrets = f.readline().strip()
|
db_secrets = f.readline().strip()
|
||||||
|
|
||||||
engine = create_engine(db_secrets)
|
engine = create_engine(db_secrets, connect_args={"connect_timeout": 8})
|
||||||
del db_secrets
|
del db_secrets
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from db import engine, User
|
|||||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
|
from sqlalchemy.exc import OperationalError
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseSettings):
|
class Config(BaseSettings):
|
||||||
@ -47,10 +48,13 @@ def get_password_hash(password):
|
|||||||
|
|
||||||
def get_user(username: str | None):
|
def get_user(username: str | None):
|
||||||
if username:
|
if username:
|
||||||
|
try:
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
return session.exec(
|
return session.exec(
|
||||||
select(User).where(User.username == username)
|
select(User).where(User.username == username)
|
||||||
).one_or_none()
|
).one_or_none()
|
||||||
|
except OperationalError:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def authenticate_user(username: str, password: str):
|
def authenticate_user(username: str, password: str):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user