/** * Funkce vracející výchozí připojení k databázi * @param string $ppType * @param User $user * @return PpConnection */ public function getDefaultPpConnection($ppType, User $user) { $config = $this->getPreprocessingDatabaseConfig($ppType); $ppConnection = new PpConnection(); $ppConnection->type = $ppType; $ppConnection->dbApi = !empty($config['preprocessingApi']) ? $config['preprocessingApi'] : null; $ppConnection->dbServer = !empty($config['server']) ? $config['server'] : null; $ppConnection->dbPort = !empty($config['port']) ? $config['port'] : null; //konfigurace připojení k DB $ppConnection->dbName = str_replace('*', $user->userId, $config['_database']); $ppConnection->dbUsername = str_replace('*', $user->userId, $config['_username']); //heslo nastavujeme, pokud pro daný typ databáze není nastaveno na FALSE if (isset($config['_password'])) { if (!$config['_password']) { $ppConnection->dbPassword = ''; } else { $ppConnection->dbPassword = $config['_password']; } } else { $ppConnection->dbPassword = $user->getDbPassword(); } return $ppConnection; }
/** * @param User $user * @return bool */ public function saveUser(User &$user) { if ($user->isDetached() && $user->getDbPassword() == '') { //při ukládání nového uživatele mu přiřadíme heslo... $user->setDbPassword(StringsHelper::randString(8)); } try { $apiKey = $user->apiKey; } catch (\Exception $e) { $apiKey = ''; } if ($apiKey == '') { //při ukládání uživatele bez apiKey mu vygenerujeme náhodný $user->apiKey = StringsHelper::randString(20) . round(rand(3911, 89301)) . StringsHelper::randString(20); } return $this->usersRepository->persist($user); }
/** * Funkce vracející heslo k DB na základě údajů klienta * @param User $user * @return string */ private function getUserDbPassword(User $user) { return Strings::substring($user->getDbPassword(), 2, 3) . Strings::substring(sha1($user->userId . $user->getDbPassword()), 4, 5); }