fix
This commit is contained in:
@@ -53,6 +53,11 @@ async def get_current_user(token: str = Depends(oauth2_scheme), db: Session = De
|
|||||||
user = db.query(models.User).filter(models.User.username == token_data.username).first()
|
user = db.query(models.User).filter(models.User.username == token_data.username).first()
|
||||||
if user is None:
|
if user is None:
|
||||||
print(f"DEBUG AUTH: User {token_data.username} not found in DB")
|
print(f"DEBUG AUTH: User {token_data.username} not found in DB")
|
||||||
|
# Dump all users to see what happened
|
||||||
|
all_users = db.query(models.User).all()
|
||||||
|
print("DEBUG AUTH: Current users in DB:")
|
||||||
|
for u in all_users:
|
||||||
|
print(f" - ID: {u.id}, Username: '{u.username}', Email: '{u.email}'")
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
|
|
||||||
print(f"DEBUG AUTH: User found: {user.username}, Is Admin: {user.is_admin}")
|
print(f"DEBUG AUTH: User found: {user.username}, Is Admin: {user.is_admin}")
|
||||||
|
|||||||
@@ -44,22 +44,30 @@ async def update_user(user_id: int, user_update: schemas.UserUpdate, background_
|
|||||||
if not db_user:
|
if not db_user:
|
||||||
raise HTTPException(status_code=404, detail="User not found")
|
raise HTTPException(status_code=404, detail="User not found")
|
||||||
|
|
||||||
|
print(f"DEBUG UPDATE: Updating user {user_id} with data: {user_update}")
|
||||||
|
|
||||||
if user_update.password:
|
if user_update.password:
|
||||||
|
print("DEBUG UPDATE: Updating password")
|
||||||
db_user.hashed_password = auth_utils.get_password_hash(user_update.password)
|
db_user.hashed_password = auth_utils.get_password_hash(user_update.password)
|
||||||
# Send email on password change
|
# Send email on password change
|
||||||
background_tasks.add_task(email.send_welcome_email, db_user.email, db_user.username, user_update.password)
|
background_tasks.add_task(email.send_welcome_email, db_user.email, db_user.username, user_update.password)
|
||||||
|
|
||||||
if user_update.email:
|
if user_update.email:
|
||||||
|
print(f"DEBUG UPDATE: Updating email to {user_update.email}")
|
||||||
db_user.email = user_update.email
|
db_user.email = user_update.email
|
||||||
if user_update.username:
|
if user_update.username:
|
||||||
|
print(f"DEBUG UPDATE: Updating username to {user_update.username}")
|
||||||
db_user.username = user_update.username
|
db_user.username = user_update.username
|
||||||
if user_update.is_active is not None:
|
if user_update.is_active is not None:
|
||||||
|
print(f"DEBUG UPDATE: Updating is_active to {user_update.is_active}")
|
||||||
db_user.is_active = user_update.is_active
|
db_user.is_active = user_update.is_active
|
||||||
if user_update.is_admin is not None:
|
if user_update.is_admin is not None:
|
||||||
|
print(f"DEBUG UPDATE: Updating is_admin to {user_update.is_admin}")
|
||||||
db_user.is_admin = user_update.is_admin
|
db_user.is_admin = user_update.is_admin
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(db_user)
|
db.refresh(db_user)
|
||||||
|
print(f"DEBUG UPDATE: User after update: id={db_user.id}, username={db_user.username}, email={db_user.email}, is_admin={db_user.is_admin}")
|
||||||
return db_user
|
return db_user
|
||||||
|
|
||||||
@router.post("/{user_id}/assign/{app_id}")
|
@router.post("/{user_id}/assign/{app_id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user