def create_admin(username, password): if len(password) < 8: click.echo("Password length too short") else: user = User(username=username, password=password, is_admin=True) if user.insert(): click.echo(f"User {username} successfully created.") else: click.echo("User with given username already exists.")
@login_manager.user_loader def load_user(user_id): db = extensions.get_db() res = db.get(doc_id=int(user_id)) if res and res["type"] == "user": return User.from_db(res) return None # prevent pytest from hanging because of running thread if 'pytest' not in sys.argv[0]: Thread(target=run_watcher, args=[app]).start() app.jinja_options["extensions"].append("jinja2.ext.do") # create admin user if it does not exist with app.app_context(): db = extensions.get_db() user_query = Query() # noqa here because tinydb requires us to explicitly specify is_admin == True if not db.search((user_query.type == "user") & (user_query.is_admin == True)): # noqa: password = token_urlsafe(32) user = User(username="******", password=password, is_admin=True) if user.insert(): app.logger.info(f"""Archivy has created an admin user as it did not exist. Username: '******', password: '******' """) from archivy import routes # noqa:
def user_fixture(test_app): user = {"username": "******", "password": "******"} user = User(**user) user.insert() return user