This commit is contained in:
Yuri Kuznetsov
2020-09-09 11:37:32 +03:00
parent fa177c41b7
commit 3fc0349550
2 changed files with 65 additions and 23 deletions

View File

@@ -29,9 +29,11 @@
namespace Espo\Core\Api;
use Exception;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\{
BadRequest,
Forbidden,
ServiceUnavailable,
};
use Espo\Core\Authentication\{
Authentication,
@@ -44,6 +46,7 @@ use Espo\Core\{
};
use StdClass;
use Exception;
/**
* Determines which auth method to use. Fetches a username and password from headers and server parameters.
@@ -156,23 +159,29 @@ class Auth
if (!$this->isEntryPoint && $hasAuthData) {
try {
$isAuthenticated = (bool) $this->authentication->login($username, $password, $request, $authenticationMethod);
} catch (Exception $e) {
}
catch (Exception $e) {
$this->processException($response, $e);
return;
}
if ($isAuthenticated) {
$this->resolve();
return;
}
}
$this->resolveUseNoAuth();
return;
}
if ($hasAuthData) {
try {
$authResult = $this->authentication->login($username, $password, $request, $authenticationMethod);
} catch (Exception $e) {
}
catch (Exception $e) {
$this->processException($response, $e);
}
@@ -185,6 +194,7 @@ class Auth
if (!$this->isXMLHttpRequest($request)) {
$showDialog = true;
}
$this->processUnauthorized($response, $showDialog);
}
}
@@ -206,6 +216,7 @@ class Auth
if ($authResult->isSuccess()) {
$this->resolve();
return;
}
@@ -219,19 +230,34 @@ class Auth
'view' => $authResult->getView(),
'token' => $authResult->getToken(),
];
$response->writeBody(json_encode($bodyData));
}
}
protected function processException(Response $response, Exception $e)
{
$reason = $e->getMessage();
if (
$e instanceof BadRequest ||
$e instanceof ServiceUnavailable ||
$e instanceof BadRequest
) {
$reason = $e->getMessage();
if ($reason) {
$response->setHeader('X-Status-Reason', $e->getMessage());
if ($reason) {
$response->setHeader('X-Status-Reason', $e->getMessage());
}
$response->setStatus($e->getCode());
$GLOBALS['log']->notice("Auth: " . $e->getMessage());
return;
}
$response->setStatus($e->getCode(), $reason);
$response->setStatus(500);
$GLOBALS['log']->error("Auth: " . $e->getMessage());
}
protected function processUnauthorized(Response $response, bool $showDialog)

View File

@@ -27,9 +27,15 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
use Espo\Core\Utils\Util;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Utils\Config;
use Espo\Core\{
Application,
Utils\Util,
Utils\File\Manager as FileManager,
Utils\Config,
Utils\Database\Helper as DatabaseHelper,
Utils\PasswordHash,
Utils\SystemRequirements,
};
class Installer
{
@@ -51,7 +57,7 @@ class Installer
protected $defaultSettings;
protected $permittedSettingList = array(
protected $permittedSettingList = [
'dateFormat',
'timeFormat',
'timeZone',
@@ -69,21 +75,23 @@ class Installer
'outboundEmailFromName',
'outboundEmailFromAddress',
'outboundEmailIsShared',
);
];
public function __construct()
{
$this->initialize();
$this->app = new \Espo\Core\Application();
$this->app = new Application();
require_once('install/core/InstallerConfig.php');
$this->installerConfig = new InstallerConfig();
require_once('install/core/SystemHelper.php');
$this->systemHelper = new SystemHelper();
$this->databaseHelper = new \Espo\Core\Utils\Database\Helper($this->getConfig());
$this->databaseHelper = new DatabaseHelper($this->getConfig());
}
protected function initialize()
@@ -93,7 +101,7 @@ class Installer
$configPath = $config->getConfigPath();
if (!file_exists($configPath)) {
$fileManager->putPhpContents($configPath, array());
$fileManager->putPhpContents($configPath, []);
}
$data = include('data/config.php');
@@ -146,7 +154,7 @@ class Installer
{
if (!isset($this->passwordHash)) {
$config = $this->getConfig();
$this->passwordHash = new \Espo\Core\Utils\PasswordHash($config);
$this->passwordHash = new PasswordHash($config);
}
return $this->passwordHash;
@@ -182,7 +190,14 @@ class Installer
protected function getLanguage()
{
if (!isset($this->language)) {
$this->language = $this->app->getContainer()->get('language');
try {
$this->language = $this->app->getContainer()->get('defaultLanguage');
} catch (Throwable $e) {
echo "Error: " . $e->getMessage();
$GLOBALS['log']->error($e->getMessage());
die;
}
}
return $this->language;
@@ -211,7 +226,7 @@ class Installer
public function getSystemRequirementList($type, $requiredOnly = false, array $additionalData = null)
{
$systemRequirementManager = new \Espo\Core\Utils\SystemRequirements($this->app->getContainer());
$systemRequirementManager = new SystemRequirements($this->app->getContainer());
return $systemRequirementManager->getRequiredListByType($type, $requiredOnly, $additionalData);
}
@@ -221,7 +236,8 @@ class Installer
try {
$pdo = $this->getDatabaseHelper()->createPdoConnection($params);
} catch (\Exception $e) {
}
catch (Exception $e) {
if ($isCreateDatabase && $e->getCode() == '1049') {
$modParams = $params;
unset($modParams['dbname']);
@@ -303,7 +319,7 @@ class Installer
try {
$result = $this->app->getContainer()->get('dataManager')->rebuild();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->auth();
$result = $this->app->getContainer()->get('dataManager')->rebuild();
}
@@ -571,7 +587,7 @@ class Installer
try {
$result &= $sth->execute();
} catch (\Exception $e) {
} catch (Exception $e) {
$GLOBALS['log']->warning('Error executing the query: ' . $query);
}