mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
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
|
@ -22,6 +22,7 @@
|
|||
namespace App\Entity\LogSystem;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
/**
|
||||
* This log entry is created when a user logs in.
|
||||
|
@ -32,6 +33,12 @@ class UserLoginLogEntry extends AbstractLogEntry
|
|||
{
|
||||
protected $typeString = "user_login";
|
||||
|
||||
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,10 +51,15 @@ class UserLoginLogEntry 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