Phpauth\Auth::addUser PHP Method

addUser() protected method

Adds a new user to database
protected addUser ( string $email, string $password, array $params = [], &$sendmail ) : integer
$email string -- email
$password string -- password
$params array -- additional params
return integer $uid
    protected function addUser($email, $password, $params = array(), &$sendmail)
    {
        $return['error'] = true;
        $query = $this->dbh->prepare("INSERT INTO {$this->config->table_users} VALUES ()");
        if (!$query->execute()) {
            $return['message'] = $this->lang["system_error"] . " #03";
            return $return;
        }
        $uid = $this->dbh->lastInsertId();
        $email = htmlentities(strtolower($email));
        if ($sendmail) {
            $addRequest = $this->addRequest($uid, $email, "activation", $sendmail);
            if ($addRequest['error'] == 1) {
                $query = $this->dbh->prepare("DELETE FROM {$this->config->table_users} WHERE id = ?");
                $query->execute(array($uid));
                $return['message'] = $addRequest['message'];
                return $return;
            }
            $isactive = 0;
        } else {
            $isactive = 1;
        }
        $password = $this->getHash($password);
        if (is_array($params) && count($params) > 0) {
            $customParamsQueryArray = array();
            foreach ($params as $paramKey => $paramValue) {
                $customParamsQueryArray[] = array('value' => $paramKey . ' = ?');
            }
            $setParams = ', ' . implode(', ', array_map(function ($entry) {
                return $entry['value'];
            }, $customParamsQueryArray));
        } else {
            $setParams = '';
        }
        $query = $this->dbh->prepare("UPDATE {$this->config->table_users} SET email = ?, password = ?, isactive = ? {$setParams} WHERE id = ?");
        $bindParams = array_values(array_merge(array($email, $password, $isactive), $params, array($uid)));
        if (!$query->execute($bindParams)) {
            $query = $this->dbh->prepare("DELETE FROM {$this->config->table_users} WHERE id = ?");
            $query->execute(array($uid));
            $return['message'] = $this->lang["system_error"] . " #04";
            return $return;
        }
        $return['error'] = false;
        return $return;
    }