def security_web_handler(sketch: Sketch):
    if sketch.auth_framework == "security_web":
        sketch.add_requirements("flask-security-too", "argon2-cffi")

        sketch.settings["default"]["SECURITY_REGISTERABLE"] = True
        sketch.settings["default"]["SECURITY_POST_LOGIN_VIEW"] = "/"
        sketch.settings["default"]["SECURITY_PASSWORD_HASH"] = "argon2"

        sketch.add_extensions("auth")

        sketch.secrets["default"]["SECURITY_PASSWORD_SALT"] = random_string()

        sketch.write_template(
            "security_web_only_tpl",
            templates.commands,
            pjoin(
                sketch.app_folder,
                "commands",
                "__init__.py",
            ),
        )

        sketch.write_template(
            "ext_security_web_only_tpl",
            templates.ext,
            pjoin(sketch.app_folder, "ext", "auth.py"),
        )

        sketch.write_template(
            "models_security_web_only_tpl",
            templates.models,
            pjoin(sketch.app_folder, "models", "user.py"),
        )

        sketch.write_template(
            "examples_security_auth_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "auth_examples.py",
            ),
        )

        sketch.write_template(
            "examples_init_security_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "__init__.py",
            ),
        )

        return True
Exemple #2
0
def create_project(args: Namespace, answers: dict):
    pf = pjoin(str(pathlib.Path().absolute()), args.project_name)
    apf = pjoin(
        str(pathlib.Path().absolute()),
        args.project_name,
        args.project_name.replace("-", "_"),
    )

    sketch = Sketch(pf, apf, answers, args)

    make_commom(sketch)

    sketch.settings["default"]["DEBUG"] = False
    sketch.settings["development"]["DEBUG"] = True
    sketch.secrets["default"]["SECRET_KEY"] = random_string(length=64)
    # TODO find a better place for this below
    sketch.template_args[
        "ADMIN_USER_ROLE_IMPORT"] = "from {}.models import User, Role".format(
            sketch.app_folder_name)

    app_type_handler(sketch)
    database_handler(sketch)
    models_handler(sketch)
    auth_handler(sketch)
    if sketch.have_api:
        api_framework_handler(sketch)
        api_auth_handler(sketch)
    commands_handler(sketch)
    handle_features(sketch)
    config_handler(sketch)

    # if args.e:
    sketch.blueprints.extend(["examples"])
    make_app(sketch)
    make_requirements(sketch)

    make_template_args(sketch)

    cleanup(sketch)

    if args.v:
        print("\nCreating virtual environment...")
        os.system(f"python3 -m venv {pf}/.venv")

    print("\n\nAll done!")
Exemple #3
0
def create_project(args: Namespace, answers: dict):
    pf = pjoin(str(pathlib.Path().absolute()), args.project_name)
    apf = pjoin(
        str(pathlib.Path().absolute()),
        args.project_name,
        args.project_name.replace("-", "_"),
    )

    sketch = Sketch(pf, apf, answers, args)

    make_commom(sketch)

    sketch.settings["default"]["DEBUG"] = False
    sketch.settings["development"]["DEBUG"] = True
    sketch.secrets["default"]["SECRET_KEY"] = random_string(length=64)

    app_type_handler(sketch)
    database_handler(sketch)
    auth_handler(sketch)
    if sketch.have_api:
        api_framework_handler(sketch)
        api_auth_handler(sketch)

    handle_features(sketch)
    config_handler(sketch)

    # if args.e:
    sketch.blueprints.extend(["examples"])
    make_app(sketch)
    make_requirements(sketch)

    make_template_args(sketch)

    cleanup(sketch)

    if args.v:
        print("\ncreating virtual environment...")
        os.system(f"python -m venv {pf}/.venv")

    print("\n\nAll done!")
Exemple #4
0
def basicauth_web_handler(sketch: Sketch):
    if sketch.auth_framework == "basicauth":
        sketch.add_requirements("flask-basicAuth")
        sketch.secrets["default"]["BASIC_AUTH_PASSWORD"] = "******"
        sketch.secrets["default"]["BASIC_AUTH_PASSWORD"] = random_string()
        return True
Exemple #5
0
def security_web_handler(sketch: Sketch):
    if sketch.auth_framework == "security":
        sketch.add_requirements("flask-security-too", "argon2-cffi")

        sketch.settings["default"]["SECURITY_REGISTERABLE"] = True
        sketch.settings["default"]["SECURITY_POST_LOGIN_VIEW"] = "/"
        sketch.settings["default"]["SECURITY_PASSWORD_HASH"] = "argon2"

        sketch.add_extensions("auth")

        sketch.secrets["default"]["SECURITY_PASSWORD_SALT"] = random_string(
            length=32)

        sketch.template_args[
            "PWD_VERIFIER_METHOD_IMPORT"] = "from flask_security import verify_password"

        sketch.template_args[
            "PWD_VERIFIER_METHOD"] = "verify_password(password, user.password)"

        sketch.write_template(
            "site_web_only_init_tpl",
            templates.site,
            pjoin(sketch.app_folder, "site", "__init__.py"),
        )

        sketch.write_template(
            "site_web_only_views_tpl",
            templates.site,
            pjoin(sketch.app_folder, "site", "views.py"),
        )

        sketch.write_template(
            "security_web_only_tpl",
            templates.commands,
            pjoin(
                sketch.app_folder,
                "commands",
                "__init__.py",
            ),
            mode="w",
        )

        sketch.write_template(
            "ext_security_web_only_tpl",
            templates.ext,
            pjoin(sketch.app_folder, "ext", "auth.py"),
        )

        sketch.write_template(
            "models_security_tpl",
            templates.models,
            pjoin(sketch.app_folder, "models", "user.py"),
        )

        sketch.write_template(
            "examples_security_auth_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "auth_examples.py",
            ),
        )

        sketch.write_template(
            "examples_init_auth_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "__init__.py",
            ),
        )

        return True
Exemple #6
0
def security_web_handler(sketch: Sketch):
    if sketch.auth_framework == "security":
        sketch.add_requirements(reqs.FLASK_SECURITY_TOO, reqs.ARGON2)

        sketch.settings["default"]["SECURITY_REGISTERABLE"] = True
        sketch.settings["default"]["SECURITY_POST_LOGIN_VIEW"] = "/"
        sketch.settings["default"]["SECURITY_PASSWORD_HASH"] = "argon2"

        sketch.add_extensions("auth")

        sketch.secrets["default"]["SECURITY_PASSWORD_SALT"] = random_string(
            length=32)

        sketch.template_args[
            "PWD_VERIFIER_METHOD_IMPORT"] = "from flask_security import verify_password"

        sketch.template_args[
            "PWD_VERIFIER_METHOD"] = "verify_password(password, user.password)"

        sketch.write_template(
            "site_web_only_init_tpl",
            templates.site,
            pjoin(sketch.app_folder, "site", "__init__.py"),
        )

        sketch.write_template(
            "site_web_only_views_tpl",
            templates.site,
            pjoin(sketch.app_folder, "site", "views.py"),
        )

        if sketch.database == "mongodb":
            auth_tpl = "ext_auth_security_mongo_tpl"
        else:
            auth_tpl = "ext_security_web_only_tpl"

        sketch.write_template(
            auth_tpl,
            templates.ext,
            pjoin(sketch.app_folder, "ext", "auth.py"),
        )

        sketch.write_template(
            "examples_security_auth_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "auth_examples.py",
            ),
        )

        sketch.write_template(
            "examples_init_auth_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "__init__.py",
            ),
        )

        return True