@router.post('/login')
def login(request : OAuth2PasswordRequestForm = Depends(), db : Session = Depends(database.get_db)):
room = db.query(models.Room).filter(models.Room.name == request.username).first()
print(request.username)
if not room:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
detail=f'Not found: {request.username}')
if not hashing.Hash.verify(room.password, request.password):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
detail=f'Password id bed :(')
#generujemy token i zwracamy
# access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = create_access_token(data={"sub": room.name})
return {"access_token": access_token, "token_type": "bearer", "id_room":room.id}