fix(task7): invalidate tokens on password change or reset
This commit is contained in:
@@ -180,6 +180,7 @@ def update_user(
|
||||
if password is not None and password != "":
|
||||
validate_password(password, email=data.get("email", user.email))
|
||||
user.password_hash = hash_password(password)
|
||||
user.token_version = (user.token_version or 0) + 1
|
||||
|
||||
for k, v in data.items():
|
||||
setattr(user, k, v)
|
||||
@@ -243,5 +244,6 @@ def reset_user_password(
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found.")
|
||||
validate_password(payload.new_password, email=user.email)
|
||||
user.password_hash = hash_password(payload.new_password)
|
||||
user.token_version = (user.token_version or 0) + 1
|
||||
db.commit()
|
||||
return {"message": f"Password for {user.name} has been reset successfully."}
|
||||
|
||||
Reference in New Issue
Block a user