<?php
namespace App\Document\Security;
use App\Document\Authorization\UserLevelAuthorization;
use App\Document\Common\LegalEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique;
/**
* @MongoDB\Document(repositoryClass="App\Repository\Security\UserRepository")
* @MongoDBUnique(fields="username")
*/
class User implements UserInterface, \Serializable
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\Field(type="string")
*/
protected $username;
/**
* @MongoDB\Field(type="string")
*/
protected $password;
/**
* @MongoDB\Field(type="string")
* @Assert\Blank()
*/
protected $salt;
/**
* @MongoDB\Field(type="boolean")
*/
protected $isActive;
/**
* @MongoDB\Field(type="boolean")
*/
protected $status;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Security\Role",cascade={"persist"})
*/
protected $role;
/**
* @MongoDB\EmbedOne (targetDocument="App\Document\Security\UserProfile")
*/
protected $userProfile;
/**
* @MongoDB\Field(type="string")
*/
protected $apiKey;
/**
* @MongoDB\Field(type="date")
*/
protected $lastLoginAt;
/**
* @MongoDB\ReferenceMany(targetDocument="App\Document\Device\Device",cascade={"persist"})
*/
protected $blockedDevices;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Common\LegalEntity")
*/
protected $legalEntity;
/**
* @MongoDB\Field(type="string")
*/
protected $legalEntityMeta;
/**
* @MongoDB\Field(type="string")
*/
protected $primaryRole;
/**
* @MongoDB\Field(type="integer")
*/
protected $accessRoleLevel;
/**
* @MongoDB\Field(type="integer")
*/
protected $systemAccessLevel;
/**
* @MongoDB\ReferenceOne(targetDocument="App\Document\Authorization\UserLevelAuthorization",cascade={"persist"})
*/
protected $userLevelAuthorization;
public function __construct()
{
$this->userProfile = new UserProfile();
$this->isActive = true;
$this->status = true;
$this->accessRoleLevel = 0;
}
public function getRoles()
{
$roles[] = $this->role->getMetaCode();
return $roles;
}
/**
* @return mixed
*/
public function getPrimaryRole()
{
return $this->primaryRole;
}
/**
* @param mixed $primaryRole
*/
public function setPrimaryRole($primaryRole)
{
$this->primaryRole = $primaryRole;
}
/**
* @return string|null
*/
public function getPassword()
{
return $this->password;
}
public function setPassword($password): User
{
$this->password = $password;
return $this;
}
public function getSalt()
{
return $this->salt;
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
$this->userProfile,
// see section on salt below
// $this->salt,
));
}
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
$this->userProfile,
// see section on salt below
// $this->salt
) = unserialize($serialized, array('allowed_classes' => true));
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return bool
*/
public function getIsActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive($isActive): void
{
$this->isActive = $isActive;
}
/**
* @return bool
*/
public function getStatus(): bool
{
return $this->status;
}
/**
* @param bool $status
*/
public function setStatus($status): void
{
$this->status = $status;
}
/**
* @return Role
*/
public function getRole()
{
return $this->role;
}
/**
* @param mixed $role
*/
public function setRole($role): void
{
$this->role = $role;
}
/**
* @return UserProfile
*/
public function getUserProfile():UserProfile
{
return $this->userProfile;
}
/**
* @param mixed $userProfile
*/
public function setUserProfile($userProfile): void
{
$this->userProfile = $userProfile;
}
/**
* @return mixed
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* @param mixed $apiKey
*/
public function setApiKey($apiKey): void
{
$this->apiKey = $apiKey;
}
/**
* @return mixed
*/
public function getLastLoginAt()
{
return $this->lastLoginAt;
}
/**
* @param mixed $lastLoginAt
*/
public function setLastLoginAt($lastLoginAt): void
{
$this->lastLoginAt = $lastLoginAt;
}
/**
* @return mixed
*/
public function getBlockedDevices()
{
return $this->blockedDevices;
}
/**
* @param mixed $blockedDevices
*/
public function setBlockedDevices($blockedDevices): void
{
$this->blockedDevices = $blockedDevices;
}
/**
* @return LegalEntity $legalEntity
*/
public function getLegalEntity()
{
return $this->legalEntity;
}
/**
* @param mixed $legalEntity
*/
public function setLegalEntity($legalEntity): void
{
$this->legalEntity = $legalEntity;
}
/**
* @param mixed $salt
*/
public function setSalt($salt): void
{
$this->salt = $salt;
}
/**
* @return mixed
*/
public function getLegalEntityMeta()
{
return $this->legalEntityMeta;
}
/**
* @param mixed $legalEntityMeta
*/
public function setLegalEntityMeta($legalEntityMeta): void
{
$this->legalEntityMeta = $legalEntityMeta;
}
/**
* @return int
*/
public function getAccessRoleLevel(): int
{
return $this->accessRoleLevel;
}
/**
* @param int $accessRoleLevel
*/
public function setAccessRoleLevel(int $accessRoleLevel): void
{
$this->accessRoleLevel = $accessRoleLevel;
}
/**
* @return ?UserLevelAuthorization
*/
public function getUserLevelAuthorization():?UserLevelAuthorization
{
return $this->userLevelAuthorization;
}
/**
* @param mixed $userLevelAuthorization
*/
public function setUserLevelAuthorization($userLevelAuthorization): void
{
$this->userLevelAuthorization = $userLevelAuthorization;
}
/**
* @return mixed
*/
public function getSystemAccessLevel()
{
return $this->systemAccessLevel;
}
/**
* @param mixed $systemAccessLevel
*/
public function setSystemAccessLevel($systemAccessLevel): void
{
$this->systemAccessLevel = $systemAccessLevel;
}
}