This commit is contained in:
n1rwana 2023-08-08 23:52:52 +03:00
parent 0997ee1ca9
commit 1ef08ae1b7
No known key found for this signature in database
GPG key ID: 1D319A83686EC843
3 changed files with 9 additions and 4 deletions

View file

@ -131,5 +131,10 @@ abstract class DBEntity
$this->changes = []; $this->changes = [];
} }
function getTableName(): string
{
return $this->getTable()->getName();
}
use \Nette\SmartObject; use \Nette\SmartObject;
} }

View file

@ -28,7 +28,7 @@ class Logs
return $this->toLog($this->logs->get($id)); return $this->toLog($this->logs->get($id));
} }
function create(int $user, string $table, string $model, int $type, $object, $changes): void function create(int $user, string $table, string $model, int $type, $object, $changes, ?string $ip = NULL, ?string $useragent = NULL): void
{ {
if (OPENVK_ROOT_CONF["openvk"]["preferences"]["logs"] === true) { if (OPENVK_ROOT_CONF["openvk"]["preferences"]["logs"] === true) {
$fobject = (is_array($object) ? $object : $object->unwrap()); $fobject = (is_array($object) ? $object : $object->unwrap());
@ -65,8 +65,8 @@ class Logs
$log->setXdiff_Old(json_encode($nobject)); $log->setXdiff_Old(json_encode($nobject));
$log->setXdiff_New(json_encode($_changes)); $log->setXdiff_New(json_encode($_changes));
$log->setTs(time()); $log->setTs(time());
$log->setIp(CurrentUser::i()->getIP()); $log->setIp($ip ?? CurrentUser::i()->getIP());
$log->setUserAgent(CurrentUser::i()->getUserAgent()); $log->setUserAgent($useragent ?? CurrentUser::i()->getUserAgent());
$log->save(); $log->save();
} }
} }

View file

@ -130,7 +130,7 @@ final class AuthPresenter extends OpenVKPresenter
} }
$this->authenticator->authenticate($chUser->getId()); $this->authenticator->authenticate($chUser->getId());
(new Logs)->create($user->getId(), "profiles", "openvk\\Web\\Models\\Entities\\User", 0, $user, $user); (new Logs)->create($user->getId(), "profiles", "openvk\\Web\\Models\\Entities\\User", 0, $user, $user, $_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"]);
$this->redirect("/id" . $user->getId()); $this->redirect("/id" . $user->getId());
$user->save(); $user->save();
} }