fix: resolve audit report gaps across bulk imports, auth, scoping, and exports

This commit is contained in:
Atharv1705
2026-11-16 13:03:41 +05:30
parent ee9390a2a0
commit f356442900
25 changed files with 1994 additions and 45 deletions
+29 -1
View File
@@ -6,13 +6,19 @@ from sqlalchemy.orm import Session, joinedload
from ..core.db import get_db
from ..core.deps import get_current_user
from ..core.exceptions import CodedHTTPException
from ..core.security import create_access_token, verify_password
from ..core.security import create_access_token, hash_password, verify_password
from ..models.masters import User
from ..schemas.auth import LoginRequest, TokenResponse, UserOut
from ..services.settings_service import get_demo_as_of_date
from pydantic import BaseModel, Field
router = APIRouter(prefix="/auth", tags=["auth"])
class ChangePasswordRequest(BaseModel):
current_password: str
new_password: str = Field(..., min_length=6)
MAX_LOGIN_ATTEMPTS = 15
LOGIN_WINDOW_SECONDS = 60.0
_login_attempts: dict[str, deque[float]] = defaultdict(deque)
@@ -91,3 +97,25 @@ def get_me(
db: Session = Depends(get_db),
):
return _build_user_out(current_user, db)
@router.post("/change-password")
def change_password(
payload: ChangePasswordRequest,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db),
):
if not verify_password(payload.current_password, current_user.password_hash):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Current password is incorrect.",
)
new_pass = payload.new_password.strip()
if len(new_pass) < 6:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="New password must be at least 6 characters.",
)
current_user.password_hash = hash_password(new_pass)
db.commit()
return {"message": "Password changed successfully."}