From 0871126410923539ee878486c42ee8cc419bd511 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 11 Mar 2025 13:12:15 +0000 Subject: [PATCH] feat: Update endpoint login --- app/api/endpoints/login.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/app/api/endpoints/login.py b/app/api/endpoints/login.py index 6ed4dac..74fa893 100644 --- a/app/api/endpoints/login.py +++ b/app/api/endpoints/login.py @@ -1,7 +1,32 @@ -from fastapi import APIRouter +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session +from typing import Optional +from models import User +from database import get_db +from utils import send_reset_password_email router = APIRouter() -@router.post("/login") -async def login(username: str, password: str): - return {"message": "User logged in successfully", "username": username} \ No newline at end of file +@router.post("/forgot-password", status_code=status.HTTP_200_OK) +async def forgot_password(email: str, db: Session = Depends(get_db)): + """ + Endpoint for initiating the forgot password process. + + Args: + email (str): The email address of the user who forgot their password. + db (Session, optional): The database session object. Defaults to Depends(get_db). + + Raises: + HTTPException: If the email address is not found in the database. + + Returns: + dict: A success message indicating that the reset password email has been sent. + """ + user = db.query(User).filter(User.email == email).first() + if not user: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User with this email not found") + + # Generate and send reset password email + send_reset_password_email(user.email, user.id) + + return {"message": "Reset password email sent successfully"} \ No newline at end of file