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())
def add_bot_for_user(bot: Text, email: Text): try: user = User.objects().get(email=email, status=True) user.bot.append(bot) user.save() except DoesNotExist: raise AppException('User not found')
def get_user(email: str): """ fetch user details :param email: user login id :return: user details """ try: return User.objects().get(email=email).to_mongo().to_dict() except: raise DoesNotExist("User does not exist!")
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())
def test_add_bot_for_existing_user(self): bot_response = AccountProcessor.add_bot("test_version_2", pytest.account, "*****@*****.**", False) bot = Bot.objects(name="test_version_2").get().to_mongo().to_dict() assert bot['_id'].__str__() == bot_response['_id'].__str__() user = User.objects(email="*****@*****.**").get() assert len(user.bot) == 2 config = Configs.objects( bot=bot['_id'].__str__()).get().to_mongo().to_dict() assert config['language'] assert config['pipeline'][6]['name'] == 'FallbackClassifier' assert config['pipeline'][6]['threshold'] == 0.7 assert config['policies'][2]['name'] == 'RulePolicy' assert config['policies'][2][ 'core_fallback_action_name'] == "action_default_fallback" assert config['policies'][2]['core_fallback_threshold'] == 0.3 assert Rules.objects(bot=bot['_id'].__str__()).get() assert Responses.objects(name='utter_default', bot=bot['_id'].__str__(), status=True).get()
async def overwrite_password(token: str, password: str): """ Changes the user's password :param token: unique token from the password reset page :param password: new password entered by the user :return: mail id, mail subject and mail body """ if Utility.check_empty_string(password): raise AppException("password cannot be empty or blank") email = Utility.verify_token(token) user = User.objects().get(email=email) user.password = Utility.get_password_hash(password.strip()) user.user = email user.timestamp = datetime.utcnow user.save() subject = Utility.email_conf['email']['templates'][ 'password_changed_subject'] body = Utility.email_conf['email']['templates'][ 'password_changed_body'] return email, subject, body