feat: Update endpoint login

This commit is contained in:
Backend IM Bot 2025-03-11 13:12:15 +00:00
parent b92e35db55
commit 0871126410

View File

@ -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 = APIRouter()
@router.post("/login") @router.post("/forgot-password", status_code=status.HTTP_200_OK)
async def login(username: str, password: str): async def forgot_password(email: str, db: Session = Depends(get_db)):
return {"message": "User logged in successfully", "username": username} """
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"}