Julio Montoya 12 years ago
parent 8a7cd31f17
commit c2e994f52c
  1. 27
      main/inc/Entity/Role.php
  2. 47
      main/inc/Entity/User.php

@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="roles")
* @ORM\Entity()
*/
class Role extends SymfonyRole
class Role extends SymfonyRole implements \Serializable
{
/**
* @ORM\Column(name="id", type="integer")
@ -95,5 +95,30 @@ class Role extends SymfonyRole
return $this;
}
/**
* @see \Serializable::serialize()
*/
public function serialize()
{
/*
* ! Don't serialize $users field !
*/
return \serialize(array(
$this->id,
$this->role
));
}
/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list(
$this->id,
$this->role
) = \unserialize($serialized);
}
}

@ -13,7 +13,7 @@ use Symfony\Component\Security\Core\User\AdvancedUserInterface;
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="Entity\Repository\UserRepository")
*/
class User implements AdvancedUserInterface
class User implements AdvancedUserInterface, \Serializable
{
/**
* @var integer
@ -222,6 +222,7 @@ class User implements AdvancedUserInterface
private $classes;
/**
* @var ArrayCollection
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
* @ORM\JoinTable(
* name="users_roles",
@ -236,6 +237,8 @@ class User implements AdvancedUserInterface
*/
private $salt;
private $isActive;
/**
*
*/
@ -246,8 +249,15 @@ class User implements AdvancedUserInterface
$this->classes = new ArrayCollection();
$this->roles = new ArrayCollection();
$this->salt = sha1(uniqid(null, true));
$this->isActive = true;
}
public function getIsActive()
{
return $this->active == 1;
}
/**
* @inheritDoc
*/
@ -287,7 +297,6 @@ class User implements AdvancedUserInterface
{
}
/**
* @inheritDoc
*/
@ -296,6 +305,40 @@ class User implements AdvancedUserInterface
return $this->roles->toArray();
}
/**
* @see https://github.com/symfony/symfony/issues/3691
* @see \Serializable::serialize()
*/
public function serialize()
{
/*
* ! Don't serialize $roles field !
*/
return \serialize(array(
$this->userId,
$this->username,
$this->email,
$this->salt,
$this->password,
$this->isActive
));
}
/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->userId,
$this->username,
$this->email,
$this->salt,
$this->password,
$this->isActive
) = \unserialize($serialized);
}
/**
*
* @return ArrayCollection

Loading…
Cancel
Save