/** * Create an administrator account * * @param array $params Database access data and other parameters * @param bool $silentMode Do not display any output during installing * * @return bool */ function doCreateAdminAccount(&$params, $silentMode = false) { global $error; $result = true; if ($silentMode) { ob_start(); } $login = get_magic_quotes_gpc() ? trim(stripslashes($params['login'])) : $params['login']; $password = get_magic_quotes_gpc() ? trim(stripslashes($params["password"])) : $params["password"]; if (empty($login) || empty($password)) { $result = false; $errorMsg = fatal_error(xtr('Login and password can\'t be empty.'), 'params', 'empty admin login or password'); } else { $password = md5($password); } $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($login); if (is_null($profile)) { // Register default admin account $profile = new \XLite\Model\Profile(); $profile->setLogin($login); echo xtr('Registering primary administrator profile...'); } else { // Account already exists echo xtr('Updating primary administrator profile...'); } // Add banner for Paypal express checkout on the admin dashboard if ('ru' !== XLITE_EDITION_LNG && class_exists('\\XLite\\Module\\CDev\\Paypal\\Main')) { $expressCheckout = \XLite\Module\CDev\Paypal\Main::getPaymentMethod(\XLite\Module\CDev\Paypal\Main::PP_METHOD_EC); $expressCheckout->setSetting('email', $login); $expressCheckout->setEnabled(true); \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'CDev\\Paypal', 'name' => 'show_admin_welcome', 'value' => 'Y')); } $profile->setPassword($password); $profile->setAccessLevel(100); $profile->enable(); $role = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->findOneRoot(); $profile->addRoles($role); $profile->create(); $role->addProfiles($profile); \XLite\Core\Database::getEM()->persist($role); \XLite\Core\Database::getEM()->flush(); if ($silentMode) { ob_end_clean(); } return $result; }
/** * Create an administrator account * * @param array $params Database access data and other parameters * @param bool $silentMode Do not display any output during installing * * @return bool */ function doCreateAdminAccount(&$params, $silentMode = false) { global $error; $result = true; if ($silentMode) { ob_start(); } $login = get_magic_quotes_gpc() ? trim(stripslashes($params['login'])) : $params['login']; $password = get_magic_quotes_gpc() ? trim(stripslashes($params["password"])) : $params["password"]; if (empty($login) || empty($password)) { $result = false; $errorMsg = fatal_error(xtr('Login and password can\'t be empty.')); } else { $password = md5($password); } $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($login); if (is_null($profile)) { // Register default admin account $profile = new \XLite\Model\Profile(); $profile->setLogin($login); echo xtr('Registering primary administrator profile...'); } else { // Account already exists echo xtr('Updating primary administrator profile...'); } $profile->setPassword($password); $profile->setAccessLevel(100); $profile->enable(); $role = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->findOneByName('Administrator'); $profile->addRoles($role); $profile->create(); $role->addProfiles($profile); \XLite\Core\Database::getEM()->persist($role); \XLite\Core\Database::getEM()->flush(); if ($silentMode) { ob_end_clean(); } return $result; }