/** * creates a new user and stores basic data in the database. * * @param string $login Login name * @param string $pass Password * @param integer $userId User ID * @return mixed */ public function createUser($login, $pass = '', $userId = 0) { foreach ($this->authContainer as $auth) { if (!$this->checkAuth($auth)) { return false; } } // is $login valid? $login = (string) $login; if (!$this->isValidLogin($login)) { $this->errors[] = self::ERROR_USER_LOGINNAME_TOO_SHORT; return false; } // does $login already exist? if ($this->getUserByLogin($login, false)) { $this->errors[] = self::ERROR_USER_LOGIN_NOT_UNIQUE; return false; } // set user-ID if (0 == $userId) { $this->userId = (int) $this->config->getDb()->nextId(PMF_Db::getTablePrefix() . 'faquser', 'user_id'); } else { $this->userId = $userId; } // create user entry $insert = sprintf("\n INSERT INTO\n %sfaquser\n (user_id, login, session_timestamp, member_since)\n VALUES\n (%d, '%s', %d, '%s')", PMF_Db::getTablePrefix(), $this->getUserId(), $this->config->getDb()->escape($login), $_SERVER['REQUEST_TIME'], date('YmdHis', $_SERVER['REQUEST_TIME'])); $this->config->getDb()->query($insert); if (!$this->userdata instanceof PMF_User_UserData) { $this->userdata = new PMF_User_UserData($this->config); } $data = $this->userdata->add($this->getUserId()); if (!$data) { $this->errors[] = self::ERROR_USER_CANNOT_CREATE_USERDATA; return false; } // create authentication entry if ($pass == '') { $pass = $this->createPassword(); } $success = false; foreach ($this->authContainer as $name => $auth) { if ($auth->setReadOnly()) { continue; } if (!$auth->add($login, $pass)) { $this->errors[] = self::ERROR_USER_CANNOT_CREATE_USER . 'in Auth ' . $name; } else { $success = true; } } if (!$success) { return false; } $this->perm->autoJoin($this->userId); return $this->getUserByLogin($login, false); }