rate limit
This commit is contained in:
parent
26a16388f2
commit
53993111a4
10 changed files with 35 additions and 11 deletions
Binary file not shown.
Binary file not shown.
18
backend/src/backend/internal/xml_reader.py
Normal file
18
backend/src/backend/internal/xml_reader.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
from datetime import timedelta
|
||||
from datetime import datetime
|
||||
import feedparser
|
||||
|
||||
FEED_URL="https://blauwasser-mausis.de/rss.xml"
|
||||
|
||||
def get_feed():
|
||||
feed = feedparser.parse(FEED_URL)
|
||||
# feed.entries.reverse()
|
||||
|
||||
for article in feed.entries:
|
||||
date_string = str(article["published"])
|
||||
date_object = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S %Z')
|
||||
|
||||
if date_object > (datetime.now() - timedelta(days=1)):
|
||||
print(f"Neu: {article["title"]}")
|
||||
# TODO: Send Mail to Tim to power on newsletter
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from sqlmodel import SQLModel
|
||||
from backend.internal.xml_reader import get_feed
|
||||
from .routers import users, comments
|
||||
from backend.internal.database import create_db_and_tables
|
||||
from fastapi import APIRouter
|
||||
|
|
@ -17,4 +17,6 @@ def on_startup():
|
|||
router = APIRouter()
|
||||
|
||||
app.include_router(users.router)
|
||||
app.include_router(comments.router)
|
||||
app.include_router(comments.router)
|
||||
|
||||
get_feed()
|
||||
Binary file not shown.
BIN
backend/src/backend/models/__pycache__/article.cpython-314.pyc
Normal file
BIN
backend/src/backend/models/__pycache__/article.cpython-314.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -16,9 +16,3 @@ router = APIRouter(
|
|||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
@router.post("/")
|
||||
def register_user(session: Session = Depends(get_session)):
|
||||
comment = {"test":"test"}
|
||||
comment1 = Comment.model_validate(comment)
|
||||
session.add(comment)
|
||||
session.commit()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
from pyrate_limiter import Duration
|
||||
from pyrate_limiter import Rate
|
||||
from pyrate_limiter import Limiter
|
||||
from backend.models.user import UserInfo
|
||||
from backend.internal.authentication import get_current_user
|
||||
from backend.internal.authentication import create_access_token
|
||||
|
|
@ -12,6 +15,7 @@ from backend.internal.database import get_session
|
|||
from fastapi import Depends
|
||||
from sqlmodel import Session
|
||||
from fastapi import APIRouter
|
||||
from fastapi_limiter.depends import RateLimiter
|
||||
|
||||
router = APIRouter(
|
||||
prefix="",
|
||||
|
|
@ -34,7 +38,11 @@ def register_user(new_user: NewUser, session: Session = Depends(get_session)) ->
|
|||
raise HTTPException(HTTP_400_BAD_REQUEST)
|
||||
return user.user_code
|
||||
|
||||
@router.post("/login", status_code=201) # TODO: rate limit
|
||||
@router.post(
|
||||
"/login",
|
||||
status_code=201,
|
||||
dependencies=[Depends(RateLimiter(limiter=Limiter(Rate(3, Duration.SECOND * 30))))]
|
||||
)
|
||||
def login(user_code: str = Form(), session: Session = Depends(get_session)) -> str:
|
||||
user = session.exec(select(User).where(User.user_code == user_code)).first()
|
||||
|
||||
|
|
@ -42,10 +50,12 @@ def login(user_code: str = Form(), session: Session = Depends(get_session)) -> s
|
|||
raise HTTPException(HTTP_401_UNAUTHORIZED)
|
||||
return create_access_token({"sub": user.user_code})
|
||||
|
||||
@router.post("users/forgot") # TODO: rate limit
|
||||
@router.post(
|
||||
"users/forgot",
|
||||
dependencies=[Depends(RateLimiter(limiter=Limiter(Rate(1, Duration.MINUTE))))]
|
||||
)
|
||||
def forgot_user_code(email: str = Form(), session: Session = Depends(get_session)):
|
||||
user = session.exec(select(User).where(User.email == email)).first()
|
||||
|
||||
if user is not None:
|
||||
pass # TODO: send Mail
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue