Add user

@param $postValues

@throws \Exception
513595
public function addUser($postValues)
    {
        $userObj = UserFactory::createUserFromPostValues($postValues);

        $doesItExist = $this->getUserBySlug($userObj->slug);
        if (!empty($doesItExist)) {
            throw new \Exception('Trying to add username that already exists.');
        }
        $users = $this->repository->users;
        $users[] = $userObj;
        $this->repository->users = $users;
        $this->save();
    }
1030441
public function insert(Directory_User $postBody, $optParams = array())
  {
    $params = array('postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('insert', array($params), "Directory_User");
  }
414139
protected function alterPostedValues(array $postedValues)
    {
        foreach ($this->getMeta() as $key => $fieldMeta) {
            /** @var \stdClass $fieldMeta */
            if ($fieldMeta->type === 'checkbox') {
                $prestaShopName = $fieldMeta->collection . '_' . $key;
                if (isset($postedValues[$prestaShopName])) {
                    $postedValues[$key] = $postedValues[$prestaShopName];
                    unset($postedValues[$prestaShopName]);
                }
            }
        }
        return $postedValues;
    }
205329
public function insertRecordIntoIndex($fieldValues)
    {
        $queryBuilder = Db::getQueryBuilder('tx_kesearch_index');
        $addQueryPartFor = $this->getQueryPartForAdditionalFields($fieldValues);

        $queryArray = array();
        $queryArray['set'] = 'SET
			@pid = ' . $queryBuilder->quote($fieldValues['pid'], \PDO::PARAM_INT) . ',
			@title = ' . $queryBuilder->quote($fieldValues['title'], \PDO::PARAM_STR) . ',
			@type = ' . $queryBuilder->quote($fieldValues['type'], \PDO::PARAM_STR) . ',
			@targetpid = ' . $queryBuilder->quote($fieldValues['targetpid'], \PDO::PARAM_INT) . ',
			@content = ' . $queryBuilder->quote($fieldValues['content'], \PDO::PARAM_STR) . ',
			@tags = ' . $queryBuilder->quote($fieldValues['tags'], \PDO::PARAM_STR) . ',
			@params = ' . $queryBuilder->quote($fieldValues['params'], \PDO::PARAM_STR) . ',
			@abstract = ' . $queryBuilder->quote($fieldValues['abstract'], \PDO::PARAM_STR) . ',
			@language = ' . $queryBuilder->quote($fieldValues['language'], \PDO::PARAM_INT) . ',
			@starttime = ' . $queryBuilder->quote($fieldValues['starttime'], \PDO::PARAM_INT) . ',
			@endtime = ' . $queryBuilder->quote($fieldValues['endtime'], \PDO::PARAM_INT) . ',
			@fe_group = ' . $queryBuilder->quote($fieldValues['fe_group'], \PDO::PARAM_INT) . ',
			@tstamp = ' . $queryBuilder->quote($fieldValues['tstamp'], \PDO::PARAM_INT) . ',
			@crdate = ' . $queryBuilder->quote($fieldValues['crdate'], \PDO::PARAM_INT)
            . $addQueryPartFor['set'] . '
		;';

        $queryArray['execute'] = 'EXECUTE insertStmt USING '
            . '@pid, '
            . '@title, '
            . '@type, '
            . '@targetpid, '
            . '@content, '
            . '@tags, '
            . '@params, '
            . '@abstract, '
            . '@language, '
            . '@starttime, '
            . '@endtime, '
            . '@fe_group, '
            . '@tstamp, '
            . '@crdate'
            . $addQueryPartFor['execute'] . ';';

        try  {
            Db::getDatabaseConnection('tx_kesearch_index')->exec($queryArray['set']);
            Db::getDatabaseConnection('tx_kesearch_index')->exec($queryArray['execute']);
        } catch (\Exception $e) {
            $this->logger->error($e->getMessage());
        }

    }
998997
public function Validate($FormPostValues) {
      $this->Validation->ApplySchema($this->Data);
      // Validate the form posted values
      return $this->Validation->Validate($FormPostValues);
   }
337223
public function addRole(ArrayHash $values): void
	{
		if ($this->isAjax()) {
			try {
				$role = new AclRole;
				$this->orm->aclRoles->attach($role);
				$role->setName($values->name);
				$role->title = $values->title;
				$role->parent = $values->parent;

				$this->orm->persistAndFlush($role);

				$this->flashNotifier->success('default.dataSaved');
				$this['rolesList']->reload();
			} catch (UniqueConstraintViolationException $ex) {
				$this->flashNotifier->error('cms.permissions.duplicityName');
			} catch (InvalidArgumentException $ex) {
				$this->flashNotifier->error('cms.permissions.invalidName');
			}
		} else {
			$this->terminate();
		}
	}
1234638
private function addUsers($users)
    {
        if (!is_array($users)) {
            return false;
        }

        foreach ($users as $username => $data) {
            if ($username == '' || !$this->isString($username)) {
                throw new MemoryException('Cannot store a user that doesn\'t have a username.');
            }

            if (!isset($data['password'])) {
                $data['password'] = '';
            }

            if (!isset($data['roles']) || empty($data['roles'])) {
                $data['roles'] = [];
            } else {
                $data['roles'] = (array)$data['roles'];
            }

            $this->users[$username] = $data;
        }

        return true;
    }
88869
def add_user(self, attrs):
        
        username = attrs[self.key]
        if username in self.users:
            raise UserAlreadyExists(username, self.backend_name)
        self.users[username] = attrs
        self.users[username]['groups'] = set([])
1206871
public function addUserToSet()
    {
        $aChosenUsr = $this->_getActionIds('oxuser.oxid');
        $soxId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        // adding
        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('all')) {
            $sUserTable = $this->_getViewName('oxuser');
            $aChosenUsr = $this->_getAll($this->_addFilter("select $sUserTable.oxid " . $this->_getQuery()));
        }
        if ($soxId && $soxId != "-1" && is_array($aChosenUsr)) {
            foreach ($aChosenUsr as $sChosenUsr) {
                $oObject2Delivery = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
                $oObject2Delivery->init('oxobject2delivery');
                $oObject2Delivery->oxobject2delivery__oxdeliveryid = new \OxidEsales\Eshop\Core\Field($soxId);
                $oObject2Delivery->oxobject2delivery__oxobjectid = new \OxidEsales\Eshop\Core\Field($sChosenUsr);
                $oObject2Delivery->oxobject2delivery__oxtype = new \OxidEsales\Eshop\Core\Field("oxdelsetu");
                $oObject2Delivery->save();
            }
        }
    }
305334
public function addFile($postValues)
    {
        $destinationPath = $this->getDestinationPath();

        $filename = $this->validateFilename($postValues['name'], $destinationPath);
        $destination = $destinationPath . '/' . $filename;

        if ('0' != $postValues['error']) {
            throw new \RuntimeException('Error uploading file. Error code: ' . $postValues['error']);
        }

        if (move_uploaded_file($postValues['tmp_name'], $destination)) {
            $file = FileFactory::createFileFromPostValues($postValues, $filename);

            $files = $this->repository->files;
            $files[] = $file;
            $this->repository->files = $files;
            $this->save();
        } else {
            throw new \RuntimeException('Error moving uploaded file');
        }
        return $file;
    }
857703
function postAddListValue (req, res, next) {
    let key = req.body.key;
    let value = req.body.value;
    let type = req.body.type;
    let connectionId = req.body.connectionId;
    getConnection(req, res, function () {
        addListValue(key, value, type, res, next);
    }, connectionId);
}
722389
public function createAccount($userNames)
    {
        if (!is_array($userNames)) {
            $userNames = array($userNames);
        }

        foreach ($userNames as $userName) {
            if (empty($userName)) {
                continue;
            }

            if (!in_array($userName, $this->getLocalAccounts())) {

                //Do a sanity check
                if ($this->userNameExists($userName) === false) {

                    try {
                        $userId = wp_insert_user(
                            array(
                                'user_login' => $userName,
                                'user_pass' => wp_generate_password(),
                                'user_nicename' => $userName,
                                'user_email' => $this->createFakeEmail($userName),
                                'user_registered' => date('Y-m-d H:i:s'),
                                'role' =>  $this->defaultRole
                            )
                        );
                    } catch (\Exception $e) {
                        error_log("Error: Could not create a new user using bulk data (ad-api-integration).");
                    }

                } else {
                    $userId = null;
                }

                if (is_numeric($userId)) {
                    $this->setUserRole($userId);
                }
            }
        }
    }
1259532
public function addSitemapItem($postValues)
    {
        $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues);
        $sitemap = $this->repository->sitemap;
        $sitemap[] = $sitemapObject;
        $this->repository->sitemap = $sitemap;
        $this->save();
    }
317696
public function add()
    {
        $this->loadModel('User.Users');
        $user = $this->Users->newEntity();
        $user = $this->Users->attachFields($user);
        $languages = LocaleToolbox::languagesList();
        $roles = $this->Users->Roles->find('list', [
            'conditions' => [
                'id NOT IN' => [ROLE_ID_AUTHENTICATED, ROLE_ID_ANONYMOUS]
            ]
        ]);

        if ($this->request->data()) {
            $user->accessible('id', false);
            $data = $this->request->data;

            if (isset($data['welcome_message'])) {
                $sendWelcomeMessage = (bool)$data['welcome_message'];
                unset($data['welcome_message']);
            } else {
                $sendWelcomeMessage = false;
            }

            $user = $this->Users->patchEntity($user, $data);
            if ($this->Users->save($user)) {
                if ($sendWelcomeMessage) {
                    NotificationManager::welcome($user)->send();
                }

                $this->Flash->success(__d('user', 'User successfully registered!'));
                $this->redirect(['plugin' => 'User', 'controller' => 'manage', 'action' => 'edit', $user->id]);
            } else {
                $this->Flash->danger(__d('user', 'User could not be registered, please check your information.'));
            }
        }

        $this->title(__d('user', 'Register New User'));
        $this->set(compact('user', 'roles', 'languages'));
        $this->Breadcrumb->push('/admin/user/manage');
    }
140904
public function setValues(array $values)
    {
        // Since Bolt 1.4, we use 'ownerid' instead of 'username' in the DB tables. If we get an array that has an
        // empty 'ownerid', attempt to set it from the 'username'. In $this->setValue the user will be set, regardless
        // of ownerid is an 'id' or a 'username'.
        if (empty($values['ownerid']) && !empty($values['username'])) {
            $values['ownerid'] = $values['username'];
            unset($values['username']);
        }

        foreach ($values as $key => $value) {
            if ($key !== 'templatefields') {
                $this->setValue($key, $value);
            }
        }

        // If default status is set in contentttype.
        if (empty($this->values['status']) && isset($this->contenttype['default_status'])) {
            $this->values['status'] = $this->contenttype['default_status'];
        }

        $serializedFieldTypes = [
            'embed',
            'geolocation',
            'imagelist',
            'image',
            'file',
            'filelist',
            'video',
            'select',
            'templateselect',
            'checkbox',
            'repeater',
        ];
        // Check if the values need to be unserialized, and pre-processed.
        foreach ($this->values as $key => $value) {
            if ((in_array($this->fieldType($key), $serializedFieldTypes)) || ($key === 'templatefields')) {
                if (!empty($value) && is_string($value) && (substr($value, 0, 2) === 'a:' || $value[0] === '[' || $value[0] === '{')) {
                    try {
                        $unserdata = Lib::smartUnserialize($value);
                    } catch (\Exception $e) {
                        $unserdata = false;
                    }

                    if ($unserdata !== false) {
                        $this->values[$key] = $unserdata;
                    }
                }
            }

            if ($this->fieldType($key) === 'video' && is_array($this->values[$key]) && !empty($this->values[$key]['url'])) {
                $defaultValues = [
                    'html'       => '',
                    'responsive' => '',
                    'width'      => '1',
                    'height'     => '1',
                    'ratio'      => '1',
                ];

                $video = array_replace($defaultValues, $this->values[$key]);

                // update the HTML, according to given width and height
                if (!empty($video['width']) && !empty($video['height'])) {
                    $video['html'] = preg_replace("/width=(['\"])([0-9]+)(['\"])/i", 'width=${1}' . $video['width'] . '${3}', $video['html']);
                    $video['html'] = preg_replace("/height=(['\"])([0-9]+)(['\"])/i", 'height=${1}' . $video['height'] . '${3}', $video['html']);
                }

                $responsiveclass = 'responsive-video';

                // See if it's widescreen or not.
                if (!empty($video['height']) && (((int) $video['width'] / (int) $video['height']) > 1.76)) {
                    $responsiveclass .= ' widescreen';
                }

                if (strpos($video['url'], 'vimeo') !== false) {
                    $responsiveclass .= ' vimeo';
                }

                $video['responsive'] = sprintf('<div class="%s">%s</div>', $responsiveclass, $video['html']);

                // Mark them up as Twig markup.
                $video['html'] = new Markup($video['html'], 'UTF-8');
                $video['responsive'] = new Markup($video['responsive'], 'UTF-8');

                $this->values[$key] = $video;
            }

            if ($this->fieldType($key) === 'repeater' && is_array($this->values[$key]) && !$this->isRootType) {
                $originalMapping = null;
                $originalMapping[$key]['fields'] = $this->contenttype['fields'][$key]['fields'];
                $originalMapping[$key]['type'] = 'repeater';

                $mapping = $this->app['storage.metadata']->getRepeaterMapping($originalMapping);
                $repeater = new RepeatingFieldCollection($this->app['storage'], $mapping);
                $repeater->setName($key);

                foreach ($this->values[$key] as $subValue) {
                    $repeater->addFromArray($subValue);
                }

                $this->values[$key] = $repeater;
            }

            if ($this->fieldType($key) === 'date' || $this->fieldType($key) === 'datetime') {
                if ($this->values[$key] === '') {
                    $this->values[$key] = null;
                }
            }
        }

        // Template fields need to be done last
        // As the template has to have been selected
        if ($this->isRootType) {
            if (empty($values['templatefields'])) {
                $this->setValue('templatefields', []);
            } else {
                $this->setValue('templatefields', $values['templatefields']);
            }
        }
    }
1259998
public function update_user($values, $username = null)
	{
		// if no username is given, fetch the current user's namd
		$username = $username ?: $this->user->username;

		// get the current user record
		$current_values = \Model\Auth_User::query()
			->select(\Config::get('ormauth.table_columns', array()))
			->where('username', '=', $username)
			->get_one();

		// and bail out if it doesn't exist
		if (empty($current_values))
		{
			throw new \SimpleUserUpdateException('Username not found', 4);
		}

		// validate the values passed and assume the update array
		$update = array();
		if (array_key_exists('username', $values))
		{
			throw new \SimpleUserUpdateException('Username cannot be changed.', 5);
		}
		if (array_key_exists('password', $values))
		{
			if (empty($values['old_password'])
				or $current_values->password != $this->hash_password(trim($values['old_password'])))
			{
				throw new \SimpleUserWrongPassword('Old password is invalid');
			}

			$password = trim(strval($values['password']));
			if ($password === '')
			{
				throw new \SimpleUserUpdateException('Password can\'t be empty.', 6);
			}
			$update['password'] = $this->hash_password($password);
			unset($values['password']);
		}
		if (array_key_exists('old_password', $values))
		{
			unset($values['old_password']);
		}
		if (array_key_exists('email', $values))
		{
			$email = filter_var(trim($values['email']), FILTER_VALIDATE_EMAIL);
			if ( ! $email)
			{
				throw new \SimpleUserUpdateException('Email address is not valid', 7);
			}

			$matches = \Model\Auth_User::query()
				->select(\Config::get('ormauth.table_columns', array()))
				->where('email', '=', $email)
				->where('id', '!=', $current_values->id)
				->get_one();

			if ($matches)
			{
				throw new \SimpleUserUpdateException('Email address is already in use', 11);
			}

			$update['email'] = $email;
			unset($values['email']);
		}
		// deal with some simpleauth compatibility
		if (array_key_exists('group', $values))
		{
			array_key_exists('group_id', $values) or $values['group_id'] = $values['group'];
			unset($values['group']);
		}
		if (array_key_exists('group_id', $values))
		{
			if (is_numeric($values['group_id']))
			{
				$update['group_id'] = (int) $values['group_id'];
			}
			unset($values['group_id']);
		}

		// load the updated values into the object
		$current_values->from_array($update);

		$updated = false;

		// any values remaining?
		if ( ! empty($values))
		{
			// set them as EAV values
			foreach ($values as $key => $value)
			{
				if ( ! isset($current_values->{$key}) or $current_values->{$key} != $value)
				{
					if ($value === null)
					{
						unset($current_values->{$key});
					}
					else
					{
						$current_values->{$key} = $value;
					}

					// mark we've updated something
					$updated = true;
				}
			}
		}

		// check if this has changed anything
		if ($updated or $updated = $current_values->is_changed())
		{
			// and only save if it did
			$current_values->save();
		}

		// return the updated status
		return $updated;
	}
1308498
public function addUsers(ArrayCollection $users)
    {
        foreach ($users as $user) {
            $user->addTeam($this);
            $this->users->add($user);
        }
    }