Skip to content

Commit e25676d

Browse files
author
Uttam Singh
committed
Added login route
1 parent 51cf300 commit e25676d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

backend/app/routers/users.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,25 @@ def delete_user(user_id: int, db: Session = Depends(get_db)):
4545
db.delete(user)
4646
db.commit()
4747
return {"ok": True}
48+
49+
# ✅ Login route
50+
@router.post("/login")
51+
def login(
52+
email: str = Form(...),
53+
password: str = Form(...),
54+
db: Session = Depends(get_db),
55+
):
56+
user = db.query(User).filter(User.email == email).first()
57+
if not user or not bcrypt.verify(password, user.hashed_password):
58+
raise HTTPException(status_code=401, detail="Invalid email or password")
59+
60+
return {
61+
"status": "ok",
62+
"user": {
63+
"id": user.id,
64+
"name": user.name,
65+
"email": user.email,
66+
"role": user.role,
67+
"department": user.department,
68+
}
69+
}

0 commit comments

Comments
 (0)