From 6850823ae8e811c868f14d9388500597230a02c3 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Tue, 7 Jun 2022 14:54:04 +0300 Subject: [PATCH] sql_app: init_db: Add total of 3 users Signed-off-by: HeshamTB --- sql_app/init_db.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sql_app/init_db.py b/sql_app/init_db.py index 175042f..d9f6b1d 100644 --- a/sql_app/init_db.py +++ b/sql_app/init_db.py @@ -15,7 +15,33 @@ def init_user(): crud.create_user(db, user) token = auth_helper.create_access_token(data={"sub": user.username}, expires_delta=timedelta(minutes=15)) res = crud.set_user_last_token(db, user.username, token) - if not res: print("Failed to add initial token") + + user = schemas.UserCreate(email="osama@mail.none", + username="Osama", + password=config('first_user_pass')) + user_exists = crud.get_user_by_email(db, user.email) + if user_exists: return + crud.create_user(db, user) + token = auth_helper.create_access_token(data={"sub": user.username}, expires_delta=timedelta(minutes=15)) + res = crud.set_user_last_token(db, user.username, token) + + user = schemas.UserCreate(email="Hussain@mail.none", + username="Hussain", + password=config('first_user_pass')) + user_exists = crud.get_user_by_email(db, user.email) + if user_exists: return + crud.create_user(db, user) + token = auth_helper.create_access_token(data={"sub": user.username}, expires_delta=timedelta(minutes=15)) + res = crud.set_user_last_token(db, user.username, token) + + user = schemas.UserCreate(email="Assad@mail.none", + username="Assad", + password=config('first_user_pass')) + user_exists = crud.get_user_by_email(db, user.email) + if user_exists: return + crud.create_user(db, user) + token = auth_helper.create_access_token(data={"sub": user.username}, expires_delta=timedelta(minutes=15)) + res = crud.set_user_last_token(db, user.username, token) def init_door(): iot_door = schemas.IotEntityCreate(bluetooth_mac="ff:ff:ff:ff",