sql_app: implement user activate/deactivate

Previous code now rejects all user authenticated
	endpoints. Even /users/me.

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-06-08 14:37:26 +03:00
parent 35f0e8abb4
commit cdf3a6dfb1
2 changed files with 11 additions and 3 deletions

View File

@ -192,4 +192,10 @@ def record_user_connection(db: Session, user: models.User, time: datetime):
def get_sensor_data_for_room(db: Session, skip: int = 0, limit: int = 100):
data = db.query(models.RoomSensorData).offset(skip).limit(limit).all()
return data
return data
def update_user_status(db: Session, user: models.User, state: bool):
user.is_active = state
db.add(user)
db.commit()
db.refresh(user)

View File

@ -266,11 +266,13 @@ def allow_user_for_iot_entity_by_name(request: schemas.UserAllowForIotEntityRequ
@app.patch("/admin/users/{user_id}/deactiveate", tags=['Admin'])
def deactiveate_user(user_id: int, db:Session = Depends(get_db)):
return
user = crud.get_user(db, user_id)
crud.update_user_status(db, user, False)
@app.patch("/admin/users/{user_id}/activeate", tags=['Admin'])
def deactiveate_user(user_id: int, db:Session = Depends(get_db)):
return
user = crud.get_user(db, user_id)
crud.update_user_status(db, user, True)
@app.post("/admin/iotdevice/gentoken/", response_model=schemas.Token, tags=['Admin'])
def generate_token_for_iot_device(bluetooth_mac : schemas.IotBluetoothMac,