コード例 #1
0
    def add_account(name: str, user: str):
        """
        adds a new account

        :param name: account name
        :param user: user id
        :return: account id
        """
        if Utility.check_empty_string(name):
            raise AppException("Account Name cannot be empty or blank spaces")
        Utility.is_exist(
            Account,
            exp_message="Account name already exists!",
            name__iexact=name,
            status=True,
        )
        license = {
            "bots": 2,
            "intents": 10,
            "examples": 50,
            "training": 3,
            "augmentation": 5
        }
        return Account(name=name.strip(), user=user,
                       license=license).save().to_mongo().to_dict()
コード例 #2
0
    def add_user(
        email: str,
        password: str,
        first_name: str,
        last_name: str,
        account: int,
        bot: str,
        user: str,
        is_integration_user=False,
        role="trainer",
    ):
        """
        adds new user to the account

        :param email: user login id
        :param password: user password
        :param first_name: user firstname
        :param last_name:  user lastname
        :param account: account id
        :param bot: bot id
        :param user: user id
        :param is_integration_user: is this
        :param role: user role
        :return: user details
        """
        if (Utility.check_empty_string(email)
                or Utility.check_empty_string(last_name)
                or Utility.check_empty_string(first_name)
                or Utility.check_empty_string(password)):
            raise AppException(
                "Email, FirstName, LastName and password cannot be empty or blank spaces"
            )

        Utility.is_exist(
            User,
            exp_message=
            "User already exists! try with different email address.",
            email__iexact=email.strip(),
            status=True,
        )
        return (User(
            email=email.strip(),
            password=Utility.get_password_hash(password.strip()),
            first_name=first_name.strip(),
            last_name=last_name.strip(),
            account=account,
            bot=bot.strip(),
            user=user.strip(),
            is_integration_user=is_integration_user,
            role=role.strip(),
        ).save().to_mongo().to_dict())
コード例 #3
0
    def get_integration_user(bot: str, account: int):
        """
        creates integration user if it does not exist

        :param bot: bot id
        :param account: account id
        :return: dict
        """
        if not Utility.is_exist(User,
                                raise_error=False,
                                bot=bot,
                                is_integration_user=True,
                                status=True):
            email = bot + "@integration.com"
            password = Utility.generate_password()
            return AccountProcessor.add_user(
                email=email,
                password=password,
                first_name=bot,
                last_name=bot,
                account=account,
                bot=bot,
                user="******",
                is_integration_user=True,
            )
        else:
            return (User.objects(bot=bot).get(
                is_integration_user=True).to_mongo().to_dict())
コード例 #4
0
ファイル: processor.py プロジェクト: paper2code/rasa-kairon
    def add_account(name: str, user: str):
        """
        adds a new account

        :param name: account name
        :param user: user id
        :return: account id
        """
        if Utility.check_empty_string(name):
            raise AppException("Account Name cannot be empty or blank spaces")
        Utility.is_exist(
            Account,
            exp_message="Account name already exists!",
            name__iexact=name,
            status=True,
        )
        return Account(name=name.strip(),
                       user=user).save().to_mongo().to_dict()
コード例 #5
0
    async def confirm_email(token: str):
        """
        Confirms the user through link and updates the database

        :param token: the token from link
        :return: mail id, subject of mail, body of mail
        """
        email_confirm = Utility.verify_token(token)
        Utility.is_exist(
            UserEmailConfirmation,
            exp_message="Email already confirmed!",
            email__iexact=email_confirm.strip(),
        )
        confirm = UserEmailConfirmation()
        confirm.email = email_confirm
        confirm.save()
        subject = Utility.email_conf['email']['templates']['confirmed_subject']
        body = Utility.email_conf['email']['templates']['confirmed_body']
        return email_confirm, subject, body
コード例 #6
0
    def is_user_confirmed(email: str):
        """
        Checks if user is verified and raises an Exception if not

        :param email: mail id of user
        :return: None
        """
        if not Utility.is_exist(UserEmailConfirmation,
                                email__iexact=email.strip(),
                                raise_error=False):
            raise AppException("Please verify your mail")
コード例 #7
0
    def add_bot(name: str, account: int, user: str):
        """
        add a bot to account

        :param name: bot name
        :param account: account id
        :param user: user id
        :return: bot id
        """
        if Utility.check_empty_string(name):
            raise AppException("Bot Name cannot be empty or blank spaces")

        Utility.is_exist(
            Bot,
            exp_message="Bot already exists!",
            name__iexact=name,
            account=account,
            status=True,
        )
        return Bot(name=name, account=account,
                   user=user).save().to_mongo().to_dict()
コード例 #8
0
    def add_bot(name: str,
                account: int,
                user: str,
                is_new_account: bool = False):
        """
        add a bot to account

        :param name: bot name
        :param account: account id
        :param user: user id
        :param is_new_account: True if it is a new account
        :return: bot id
        """
        if Utility.check_empty_string(name):
            raise AppException("Bot Name cannot be empty or blank spaces")

        if Utility.check_empty_string(user):
            raise AppException("user cannot be empty or blank spaces")

        Utility.is_exist(
            Bot,
            exp_message="Bot already exists!",
            name__iexact=name,
            account=account,
            status=True,
        )
        bot = Bot(name=name, account=account,
                  user=user).save().to_mongo().to_dict()
        bot_id = bot['_id'].__str__()
        if not is_new_account:
            AccountProcessor.add_bot_for_user(bot_id, user)
        BotSettings(bot=bot_id, user=user).save()
        processor = MongoProcessor()
        config = processor.load_config(bot_id)
        processor.add_or_overwrite_config(config, bot_id, user)
        processor.add_default_fallback_data(bot_id, user, True, True)
        return bot