Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Astrups\SpectacleBundle\Entity;
- use \Symfony\Component\Security\Core\User\UserInterface;
- use \Doctrine\ORM\Mapping as ORM;
- /**
- * @ORM\Table(name="users")
- * @ORM\Entity
- */
- class User implements UserInterface, \Serializable
- {
- /**
- * @ORM\Column(type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @ORM\Column(type="string", length=50, unique=true)
- */
- private $username;
- /**
- * @ORM\Column(name="password_hash", type="string", length=40)
- */
- private $passwordHash;
- /**
- * @ORM\Column(type="string", length=10)
- */
- private $salt;
- /**
- * @ORM\Column(name="account_type", type="string", length=10)
- */
- private $accountType;
- /**
- * @ORM\Column(name="full_name", type="string", length=255, nullable=true)
- */
- private $fullName;
- /**
- * @ORM\Column(name="email", type="string", length=255, nullable=true)
- */
- private $email;
- public function __construct() {
- $this->salt = substr(0, 10, md5(uniqid(null, true)));
- }
- public function getUsername()
- {
- return $this->username;
- }
- public function getFullName()
- {
- return $this->fullName;
- }
- public function getPassword()
- {
- return $this->passwordHash;
- }
- public function setPassword($password, $algo='sha1', $salt=null)
- {
- if(is_null($salt)) {
- $salt = substr(0, 10, md5(uniqid(null, true)));
- }
- $this->password = sha1($password . $salt);
- }
- public function getSalt()
- {
- return $this->salt;
- }
- public function getRoles()
- {
- $roles = array();
- if($this->accountType === 'user') {
- $roles[] = 'ROLE_USER';
- }
- if($this->accountType === 'admin') {
- $roles[] = 'ROLE_ADMIN';
- }
- return $roles;
- }
- public function eraseCredentials()
- {
- }
- public function serialize()
- {
- return serialize(array(
- $this->id, $this->username, $this->passwordHash, $this->salt
- ));
- }
- public function unserialize($serialized)
- {
- list($this->id, $this->username, $this->passwordHash, $this->salt)
- = unserialize($serialized);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement