def update_user(args):
    db = db_connect()
    user = user_find(args.user)
    if user is not None:
        try:
            db.users.update_one({'_id': user['_id']}, {
                '$set': {
                    'password':
                    get_hashed_password(
                        args.password.encode(encoding='UTF-8')).decode()
                }
            },
                                upsert=False)
            print("Konker user password updated")
        except Exception as e:
            print(e)
            sys.exit(1)
    else:
        print("Konker username not found")
        sys.exit(1)
def create_user(args):
    db = db_connect()
    user = user_find(args.user)
    if user is None:
        username = args.user
        tenant_id = create_tenant(args, username)

        new_user = {
            "_id":
            username,
            "language":
            "PT_BR",
            "dateFormat":
            "DDMMYYYY",
            "zoneId":
            "AMERICA_SAO_PAULO",
            "password":
            get_hashed_password(
                args.password.encode(encoding='UTF-8')).decode(),
            "name":
            username,
            "phone":
            "",
            "notificationViaEmail":
            False,
            "tenant":
            DBRef("tenants", tenant_id)
        }

        try:
            db.users.insert_one(new_user)
            update_user_roles()
            print("Konker user created")
        except Exception as e:
            print(e)
            sys.exit(1)
    else:
        print("This konker user already exists")
        sys.exit(0)
def random_user_and_password():
    user = domain_generator(12)
    pwd = domain_generator(12)
    hashed_password = get_hashed_password(pwd)
    return (user, pwd, hashed_password)