forked from mirror/Part-DB.Part-DB-server
Add log entries on user login or logout.
This commit is contained in:
parent
d6c6b973bf
commit
c8375bfa8b
9 changed files with 323 additions and 5 deletions
|
@ -23,6 +23,7 @@ namespace App\Entity\LogSystem;
|
|||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
|
@ -32,6 +33,12 @@ class UserLogoutLogEntry extends AbstractLogEntry
|
|||
{
|
||||
protected $typeString = "user_logout";
|
||||
|
||||
public function __construct(string $ip_address, bool $anonymize = true)
|
||||
{
|
||||
$this->level = self::LEVEL_INFO;
|
||||
$this->setIPAddress($ip_address, $anonymize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the (anonymized) IP address used to login the user.
|
||||
* @return string
|
||||
|
@ -44,11 +51,18 @@ class UserLogoutLogEntry extends AbstractLogEntry
|
|||
/**
|
||||
* Sets the IP address used to login the user
|
||||
* @param string $ip The IP address used to login the user.
|
||||
* @param bool $anonymize Anonymize the IP address (remove last block) to be GPDR compliant
|
||||
* @return $this
|
||||
*/
|
||||
public function setIPAddress(string $ip): self
|
||||
public function setIPAddress(string $ip, bool $anonymize = true): self
|
||||
{
|
||||
if ($anonymize) {
|
||||
$ip = IpUtils::anonymize($ip);
|
||||
}
|
||||
|
||||
$this->extra['i'] = $ip;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue