Captcha bugfix + Logger stracktrace improvements
This commit is contained in:
parent
2a1db919e8
commit
a5e4cf6a74
@ -321,7 +321,7 @@ abstract class Request {
|
|||||||
} catch (\Throwable $err) {
|
} catch (\Throwable $err) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
$this->createError($err->getMessage());
|
$this->createError($err->getMessage());
|
||||||
$this->logger->error($err->getMessage());
|
$this->logger->severe($err);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql->setLastError("");
|
$sql->setLastError("");
|
||||||
|
@ -8,8 +8,8 @@ use Core\Objects\Context;
|
|||||||
|
|
||||||
trait Captcha {
|
trait Captcha {
|
||||||
|
|
||||||
function addCaptchaParameters(array &$parameters): void {
|
function addCaptchaParameters(Context $context, array &$parameters): void {
|
||||||
$settings = $this->context->getSettings();
|
$settings = $context->getSettings();
|
||||||
if ($settings->isCaptchaEnabled()) {
|
if ($settings->isCaptchaEnabled()) {
|
||||||
$parameters["captcha"] = new StringType("captcha");
|
$parameters["captcha"] = new StringType("captcha");
|
||||||
}
|
}
|
||||||
|
@ -756,8 +756,7 @@ namespace Core\API\User {
|
|||||||
"confirmPassword" => new StringType("confirmPassword"),
|
"confirmPassword" => new StringType("confirmPassword"),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addCaptchaParameters($parameters);
|
$this->addCaptchaParameters($context, $parameters);
|
||||||
|
|
||||||
parent::__construct($context, $externalCall, $parameters);
|
parent::__construct($context, $externalCall, $parameters);
|
||||||
$this->csrfTokenRequired = false;
|
$this->csrfTokenRequired = false;
|
||||||
}
|
}
|
||||||
@ -1033,7 +1032,7 @@ namespace Core\API\User {
|
|||||||
'email' => new Parameter('email', Parameter::TYPE_EMAIL),
|
'email' => new Parameter('email', Parameter::TYPE_EMAIL),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->addCaptchaParameters($parameters);
|
$this->addCaptchaParameters($context, $parameters);
|
||||||
parent::__construct($context, $externalCall, $parameters);
|
parent::__construct($context, $externalCall, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1121,7 +1120,7 @@ namespace Core\API\User {
|
|||||||
'email' => new Parameter('email', Parameter::TYPE_EMAIL),
|
'email' => new Parameter('email', Parameter::TYPE_EMAIL),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addCaptchaParameters($parameters);
|
$this->addCaptchaParameters($context, $parameters);
|
||||||
parent::__construct($context, $externalCall, $parameters);
|
parent::__construct($context, $externalCall, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +40,11 @@ class Logger {
|
|||||||
$this->lastLevel = null;
|
$this->lastLevel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getStackTrace(int $pop = 2): string {
|
protected function getStackTrace(int $pop = 2, ?array $debugTrace = null): string {
|
||||||
$debugTrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
if ($debugTrace === null) {
|
||||||
|
$debugTrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
|
}
|
||||||
|
|
||||||
if ($pop > 0) {
|
if ($pop > 0) {
|
||||||
array_splice($debugTrace, 0, $pop);
|
array_splice($debugTrace, 0, $pop);
|
||||||
}
|
}
|
||||||
@ -54,10 +57,17 @@ class Logger {
|
|||||||
}, $debugTrace));
|
}, $debugTrace));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function log(string $message, string $severity, bool $appendStackTrace = true): void {
|
public function log(string|\Throwable $logEntry, string $severity, bool $appendStackTrace = true): void {
|
||||||
|
|
||||||
|
$debugTrace = null;
|
||||||
|
$message = $logEntry;
|
||||||
|
if ($message instanceof \Throwable) {
|
||||||
|
$message = $logEntry->getMessage();
|
||||||
|
$debugTrace = $logEntry->getTrace();
|
||||||
|
}
|
||||||
|
|
||||||
if ($appendStackTrace) {
|
if ($appendStackTrace) {
|
||||||
$message .= "\n" . $this->getStackTrace();
|
$message .= "\n" . $this->getStackTrace(2, $debugTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastMessage = $message;
|
$this->lastMessage = $message;
|
||||||
@ -87,27 +97,27 @@ class Logger {
|
|||||||
@file_put_contents($logPath, $message);
|
@file_put_contents($logPath, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function error(string $message): string {
|
public function error(string|\Throwable $message): string {
|
||||||
$this->log($message, "error");
|
$this->log($message, "error");
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function severe(string $message): string {
|
public function severe(string|\Throwable $message): string {
|
||||||
$this->log($message, "severe");
|
$this->log($message, "severe");
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function warning(string $message): string {
|
public function warning(string|\Throwable $message): string {
|
||||||
$this->log($message, "warning", false);
|
$this->log($message, "warning", false);
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function info(string $message): string {
|
public function info(string|\Throwable $message): string {
|
||||||
$this->log($message, "info", false);
|
$this->log($message, "info", false);
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function debug(string $message, bool $appendStackTrace = false): string {
|
public function debug(string|\Throwable $message, bool $appendStackTrace = false): string {
|
||||||
$this->log($message, "debug", $appendStackTrace);
|
$this->log($message, "debug", $appendStackTrace);
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ if ($installation) {
|
|||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
$logger->error($e->getMessage());
|
$logger->severe($e);
|
||||||
$response = $router->returnStatusCode(500);
|
$response = $router->returnStatusCode(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user