예제 #1
0
def api_user_register(username, password):
    """
    Register a new user
    :param username: the username in question
    :param password: super secure password
    :return:
    """
    user = UserController.user_add(username=username, password=password)
    return "user '%s' registered" % username
예제 #2
0
파일: api.py 프로젝트: skftn/findex-gui
    def post(self):
        args = self.reqparse.parse_args()
        args = {k: v for k, v in args.items() if v is not None}

        user = UserController.user_add(username=args['username'], password=args['password'])
        if isinstance(user, Exception):
            return abort(404, message=str(user))
        else:
            return flask.jsonify(**{'success': True})
예제 #3
0
    def bootstrap(self):
        # check necessary postgres extensions
        self.create_extension(
            extension="pg_trgm",
            msg_on_activate_error="Postgres extension \"pg_trgm\" installed but "
            "could not be enabled, "
            "possibly missing administrator rights to enable "
            "pg_trgm: `CREATE EXTENSION pg_trgm;`")
        if config("findex:elasticsearch:enabled"):
            self.create_extension(
                extension="zombodb",
                msg_on_activate_error=
                "Postgres extension \"zombodb\" installed but "
                "could not be enabled.")

        # create the tables, types and indexes
        BASE.metadata.create_all(bind=self.engine)

        if config("findex:elasticsearch:enabled"):
            # check required types for es
            if not self.check_type(type_name="type_files"):
                raise DatabaseException(
                    "Postgres type `type files` not found. "
                    "Try the following SQL to rebuild the table:\n"
                    "\tDROP TYPE type_files CASCADE;\n"
                    "\tDROP TABLE files;\n")
            # check if the zombodb index is present
            if not self.check_index(table_name="files", index="idx_zdb_files"):
                raise DatabaseException(
                    "Postgres index `idx_zdb_files` not found "
                    "while ElasticSearch was enabled.\n"
                    "Try the following SQL to rebuild the table:\n"
                    "\tDROP TYPE type_files CASCADE;\n"
                    "\tDROP TABLE files;\n")
        else:
            if self.check_index(table_name="files", index="idx_zdb_files"):
                raise DatabaseException(
                    "Please remove the index `idx_zdb_files` before "
                    "using findex without ES enabled:\n"
                    "\tDROP INDEX idx_zdb_files\n"
                    "\tcurl -XDELETE <es_host> db.schema.table.index")

        from findex_gui.controllers.user.user import UserController
        from findex_gui.controllers.user.roles import default_anon_roles
        from findex_gui.controllers.resources.resources import ResourceController

        # add some default users, groups and tasks to the database
        if not UserController.user_view(username="******"):
            UserController.user_add(
                username="******",
                password=config("findex:users:default_root_password"),
                removeable=False,
                admin=True,
                skip_authorization=True)

        if not UserController.user_view(username="******"):
            UserController.user_add(
                username="******",
                password=config("findex:users:default_anon_password"),
                privileges=default_anon_roles,
                removeable=False,
                skip_authorization=True)

        if not ResourceController.get_resource_group(name="Default"):
            ResourceController.add_resource_group(
                name="Default",
                description="Default group",
                removable=False,
                skip_authorization=True,
                log_error=False,
                ignore_constraint_conflict=True)