def create_user(self, account_name, username, password=None, user_type=UserTypes.native): """ Create a new user as a unit-of-work (e.g. a single db transaction :param account_name: the str account name :param username: the str username :param password: the password to set :param user_type: The type of user to create :return: """ assert (user_type in [UserTypes.internal, UserTypes.external] and password is None) or user_type == UserTypes.native account = db_accounts.get(account_name, session=self.session) if not account: raise AccountNotFoundError('Account does not exist') usr_record = db_account_users.add(account_name=account_name, username=username, user_type=user_type, session=self.session) if password is not None: db_account_users.add_user_credential( username=username, credential_type=UserAccessCredentialTypes.password, value=password, session=self.session) usr_record = db_account_users.get(username, session=self.session) return usr_record
def create_user(self, account_name, username, creator_name, password=None): """ Create a new user as a unit-of-work (e.g. a single db transaction :param account_name: :param username: :param access_type: :param creator_name: the username of creator :return: """ account = db_accounts.get(account_name, session=self.session) if not account: raise AccountNotFoundError('Account does not exist') usr_record = db_account_users.add(account_name=account_name, username=username, created_by=creator_name, session=self.session) if password is not None: db_account_users.add_user_credential(creator=creator_name, username=username, credential_type=UserAccessCredentialTypes.password, value=password, session=self.session) usr_record = db_account_users.get(username, session=self.session) return usr_record
def create_user( self, account_name, username, password=None, user_type=UserTypes.native, user_source=None, ): """ Create a new user as a unit-of-work (e.g. a single db transaction :param account_name: the str account name :param username: the str username :param password: the password to set :param user_type: The type of user to create a :return: """ if not is_valid_username(username): raise ValueError( "username must match regex {}".format(name_validator_regex)) if user_type in [UserTypes.external] and password is not None: raise AssertionError("Cannot set password for external user type") if user_type == UserTypes.external and user_source is None: raise ValueError( "user_source cannot be None with user_type = external") account = db_accounts.get(account_name, session=self.session) if not account: raise AccountNotFoundError("Account does not exist") usr_record = db_account_users.add( account_name=account_name, username=username, user_type=user_type, user_source=user_source, session=self.session, ) if password is not None: db_account_users.add_user_credential( username=username, credential_type=UserAccessCredentialTypes.password, value=password, session=self.session, ) usr_record = db_account_users.get(username, session=self.session) return usr_record