reset endpoint + frontend reset and login pages add
This commit is contained in:
@@ -2,9 +2,11 @@ from fastapi import APIRouter, Cookie, Depends, HTTPException, Request, Response
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
|
||||
from src.cache.rate_limit import rate_limiter
|
||||
from src.messaging.producers.producers import email_producer
|
||||
from src.models.configs_read.env import env_settings
|
||||
from src.models.pydantic_models.model import UserOut
|
||||
from src.service.auth.auth import CurrentUserService, auth_service
|
||||
from src.service.users_crud.users_crud import CrudService, crud_service
|
||||
|
||||
router=APIRouter(prefix="/protected")
|
||||
oauth2_schema=OAuth2PasswordBearer(tokenUrl="/protected/token", refreshUrl="/protected/refresh")
|
||||
@@ -31,7 +33,7 @@ async def get_access_token(request: Request,
|
||||
try:
|
||||
access_token, refresh_token=await auth.login(form_data_email=form_data.username, form_data_password=form_data.password, request=request)
|
||||
except HTTPException:
|
||||
await rate_limiter.rate_limit(client_ip)
|
||||
await rate_limiter.rate_limit(client_ip, "login", 5, 60)
|
||||
raise
|
||||
|
||||
response.set_cookie(
|
||||
@@ -74,6 +76,22 @@ async def logout(response:Response,
|
||||
response.delete_cookie("refresh_token")
|
||||
return await auth.logout(refresh_token, access_token)
|
||||
|
||||
@router.post("/reset")
|
||||
async def reset(request: Request,
|
||||
email:str,
|
||||
crud:CrudService=Depends(crud_service)
|
||||
):
|
||||
|
||||
client_ip = request.headers.get('x-forwarded-for', '').split(',')[0].strip() or (request.client.host if request.client else 'unknown')
|
||||
await rate_limiter.rate_limit(client_ip, "reset", 3, 600)
|
||||
try:
|
||||
temp_password=await crud.reset_password(email)
|
||||
await email_producer.send_reset_email(email, temp_password)
|
||||
except HTTPException as exc:
|
||||
if exc.status_code!=404:
|
||||
raise
|
||||
return {"detail":"New password was sent"}
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def protected(current_user:UserOut=Depends(require_permissions()))->dict:
|
||||
|
||||
Reference in New Issue
Block a user