human hand off bug

This commit is contained in:
debu-2 2026-10-06 19:09:02 +05:30
parent 2855a20140
commit 962f991580
11 changed files with 226 additions and 34 deletions

View file

@ -23,6 +23,8 @@ from app.schemas import (
InvitePreview,
LoginRequest,
PasswordChangeRequest,
PasswordResetRequest,
PasswordResetResponse,
)
from app.services.member_invitations import get_valid_invitation
from app.services.welcome_email import send_welcome_email
@ -306,6 +308,35 @@ async def accept_invite(
)
@router.post("/reset-password", response_model=PasswordResetResponse)
async def reset_password(
payload: PasswordResetRequest,
session: AsyncSession = Depends(get_postgres_session),
) -> PasswordResetResponse:
validate_password(payload.new_password)
account = await session.scalar(
select(Account).where(Account.email == str(payload.email).lower())
)
password_hash.verify(
payload.new_password,
account.password_hash if account is not None else dummy_password_hash,
)
if account is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="No account was found for that email.",
)
if account.member_status == "invited":
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Accept your invitation email to set your password before resetting it.",
)
account.password_hash = password_hash.hash(payload.new_password)
account.must_change_password = False
await session.commit()
return PasswordResetResponse()
@router.post("/change-password", response_model=AccountRead)
async def change_password(
payload: PasswordChangeRequest,