Integrated FOSUserBundle (#216)

This commit is contained in:
Kevin Papst
2018-07-21 22:36:36 +02:00
committed by GitHub
parent 2d2525cff2
commit 75246e9db2
77 changed files with 1413 additions and 514 deletions

View File

@@ -9,10 +9,10 @@
namespace App\Entity;
use App\Validator\Constraints as KimaiAssert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
@@ -24,14 +24,14 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(
* name="users",
* uniqueConstraints={
* @ORM\UniqueConstraint(columns={"name"}),
* @ORM\UniqueConstraint(columns={"mail"})
* @ORM\UniqueConstraint(columns={"username"}),
* @ORM\UniqueConstraint(columns={"email"})
* }
* )
* @UniqueEntity("username")
* @UniqueEntity("email")
*/
class User implements UserInterface
class User extends BaseUser implements UserInterface
{
public const ROLE_CUSTOMER = 'ROLE_CUSTOMER';
public const ROLE_USER = 'ROLE_USER';
@@ -47,40 +47,7 @@ class User implements UserInterface
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=60, nullable=false, unique=true)
* @Assert\NotBlank()
* @Assert\Length(min=5, max=60)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="mail", type="string", length=160, nullable=false, unique=true)
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=254, nullable=true)
*/
private $password;
/**
* @var string
*
* @Assert\NotBlank(groups={"registration", "passwordUpdate"})
* @Assert\Length(min=6, max=4096, groups={"registration", "passwordUpdate"})
*/
private $plainPassword;
protected $id;
/**
* @var string
@@ -90,14 +57,6 @@ class User implements UserInterface
*/
private $alias;
/**
* @var bool
*
* @ORM\Column(name="active", type="boolean", nullable=false)
* @Assert\NotNull()
*/
private $active = true;
/**
* @var \DateTime
*
@@ -119,14 +78,6 @@ class User implements UserInterface
*/
private $avatar;
/**
* @var string[]
*
* @ORM\Column(type="json_array")
* @KimaiAssert\Role()
*/
private $roles = [];
/**
* @var UserPreference[]|Collection
*
@@ -139,6 +90,7 @@ class User implements UserInterface
*/
public function __construct()
{
parent::__construct();
$this->registeredAt = new \DateTime();
$this->preferences = new ArrayCollection();
}
@@ -189,107 +141,6 @@ class User implements UserInterface
return $this->alias;
}
/**
* @param bool $active
* @return $this
*/
public function setActive($active)
{
$this->active = (bool) $active;
return $this;
}
/**
* @return bool
*/
public function isActive()
{
return $this->active;
}
/**
* @param string $password
* @return $this
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Only for form editing, you don't need this method!
*
* @return string
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* Only for form editing, you don't need this method!
*
* @param string $password
* @return $this
*/
public function setPlainPassword($password)
{
$this->plainPassword = $password;
return $this;
}
/**
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* @param string $username
* @return $this
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
* @return $this
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return string
*/
@@ -328,34 +179,6 @@ class User implements UserInterface
return $this;
}
/**
* Returns the roles or permissions granted to the user for security.
*
* @return string[]
*/
public function getRoles()
{
$roles = $this->roles;
// guarantees that a user always has at least one role for security
if (empty($roles)) {
$roles[] = 'ROLE_USER';
}
return array_unique($roles);
}
/**
* @param string[] $roles
* @return $this
*/
public function setRoles(array $roles)
{
$this->roles = $roles;
return $this;
}
/**
* @return UserPreference[]|Collection
*/
@@ -419,35 +242,6 @@ class User implements UserInterface
return $this;
}
/**
* @return bool
*/
public function isEnabled()
{
return $this->isActive();
}
/**
* Returns the salt that was originally used to encode the password.
*/
public function getSalt()
{
// See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
// we're using bcrypt in security.yml to encode the password, so
// the salt value is built-in and you don't have to generate one
return;
}
/**
* Removes sensitive data from the user.
*/
public function eraseCredentials()
{
// if you had a plainPassword property, you'd nullify it here
// $this->plainPassword = null;
}
/**
* @return string
*/