Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
- use Symfony\Component\Security\Core\User\UserInterface;
- /**
- * User
- *
- * @ORM\Table(name="user")
- * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
- */
- class User implements UserInterface
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var String
- * @Orm\Column(name="username", type="string", length=64)
- */
- private $username;
- /**
- * @var
- * @Orm\Column(type="string", length=64)
- */
- private $password;
- /**
- * @var
- * @Orm\Column(type="string", length=32)
- */
- private $salt;
- /**
- * @var
- * @Orm\Column(type="string", length=64)
- */
- private $email;
- /**
- * @ORM\Column(type="json_array")
- */
- private $roles = [];
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return String
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * @param String $username
- */
- public function setUsername($username)
- {
- $this->username = $username;
- }
- /**
- * @return mixed
- */
- public function getRoles()
- {
- $roles = $this->roles;
- if (!in_array('ROLE_USER', $roles)) {
- $roles[] = 'ROLE_USER';
- }
- return $roles;
- }
- /**
- * @param mixed $roles
- */
- public function setRoles(array $roles)
- {
- $this->roles = $roles;
- }
- /**
- * @return mixed
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @param mixed $password
- */
- public function setPassword($password)
- {
- $encoder = new MessageDigestPasswordEncoder('sha1');
- $this->password = $encoder->encodePassword($password, $this->getSalt());
- }
- /**
- * @return mixed
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * @param mixed $email
- */
- public function setEmail($email)
- {
- $this->email = $email;
- }
- /**
- * Returns the salt that was originally used to encode the password.
- *
- * This can return null if the password was not encoded using a salt.
- *
- * @return string|null The salt
- */
- public function getSalt()
- {
- if (null === $this->salt) {
- $this->salt = md5(sprintf(
- '%s_%d_%f',
- uniqid(),
- rand(0, 99999),
- microtime(true)
- ));
- }
- return $this->salt;
- }
- /**
- * Removes sensitive data from the user.
- *
- * This is important if, at any given point, sensitive information like
- * the plain-text password is stored on this object.
- */
- public function eraseCredentials()
- {
- return null;
- }
- /**
- * @param mixed $salt
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- }
- }
Add Comment
Please, Sign In to add comment