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:
parent
35f0e8abb4
commit
cdf3a6dfb1
@ -193,3 +193,9 @@ 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):
|
def get_sensor_data_for_room(db: Session, skip: int = 0, limit: int = 100):
|
||||||
data = db.query(models.RoomSensorData).offset(skip).limit(limit).all()
|
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)
|
||||||
|
@ -266,11 +266,13 @@ def allow_user_for_iot_entity_by_name(request: schemas.UserAllowForIotEntityRequ
|
|||||||
|
|
||||||
@app.patch("/admin/users/{user_id}/deactiveate", tags=['Admin'])
|
@app.patch("/admin/users/{user_id}/deactiveate", tags=['Admin'])
|
||||||
def deactiveate_user(user_id: int, db:Session = Depends(get_db)):
|
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'])
|
@app.patch("/admin/users/{user_id}/activeate", tags=['Admin'])
|
||||||
def deactiveate_user(user_id: int, db:Session = Depends(get_db)):
|
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'])
|
@app.post("/admin/iotdevice/gentoken/", response_model=schemas.Token, tags=['Admin'])
|
||||||
def generate_token_for_iot_device(bluetooth_mac : schemas.IotBluetoothMac,
|
def generate_token_for_iot_device(bluetooth_mac : schemas.IotBluetoothMac,
|
||||||
|
Loading…
Reference in New Issue
Block a user