Created
September 25, 2017 12:14
-
-
Save shoebaamir7/abedffdad829557347da34624f0c95b7 to your computer and use it in GitHub Desktop.
User.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="users") | |
* @ORM\HasLifecycleCallbacks() | |
* @UniqueEntity(fields="email", message="Email already taken") | |
*/ | |
class User implements UserInterface, \Serializable { | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @ORM\Column(type="string", length=255) | |
* @Assert\NotBlank(message = "Please enter your name") | |
*/ | |
private $name; | |
/** | |
* @ORM\Column(type="string", length=255, unique=true) | |
* @Assert\NotBlank(message = "Please enter your email") | |
* @Assert\Email(message = "Please enter your correct email") | |
*/ | |
private $email; | |
/** | |
* @ORM\Column(type="string", length=255) | |
* @Assert\NotBlank(message = "Please select your role") | |
*/ | |
private $roles; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Length(max=4096) | |
*/ | |
private $plainPassword; | |
/** | |
* The below length depends on the "algorithm" you use for encoding | |
* the password, but this works well with bcrypt. | |
* | |
* @ORM\Column(type="string", length=64) | |
*/ | |
private $password; | |
/** | |
* @var datetime $created | |
* | |
* @ORM\Column(type="datetime") | |
*/ | |
protected $createdAt; | |
// other properties and methods | |
public function getName() { | |
return $this->name; | |
} | |
public function setName($name) { | |
$this->name = $name; | |
} | |
public function getEmail() { | |
return $this->email; | |
} | |
public function setEmail($email) { | |
$this->email = $email; | |
} | |
public function setRoles($roles) { | |
$this->roles = $roles; | |
} | |
public function getPlainPassword() { | |
return $this->plainPassword; | |
} | |
public function setPlainPassword($password) { | |
$this->plainPassword = $password; | |
} | |
public function getPassword() { | |
return $this->password; | |
} | |
public function setPassword($password) { | |
$this->password = $password; | |
} | |
public function getSalt() { | |
// The bcrypt algorithm doesn't require a separate salt. | |
// You *may* need a real salt if you choose a different encoder. | |
return null; | |
} | |
public function eraseCredentials() { | |
return null; | |
} | |
/** | |
* Returns the roles granted to the user. | |
* | |
* @return Role[] The user roles | |
*/ | |
public function getRoles() { | |
return array('admin'); | |
} | |
public function getUsername() { | |
return $this->email; | |
} | |
/** @see \Serializable::serialize() */ | |
public function serialize() { | |
return serialize(array( | |
$this->id, | |
$this->email, | |
$this->password, | |
// see section on salt below | |
// $this->salt, | |
)); | |
} | |
/** @see \Serializable::unserialize() */ | |
public function unserialize($serialized) { | |
list ( | |
$this->id, | |
$this->email, | |
$this->password, | |
// see section on salt below | |
// $this->salt | |
) = unserialize($serialized); | |
} | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() { | |
return $this->id; | |
} | |
/** | |
* @ORM\PrePersist | |
*/ | |
public function setCreatedAtValue() { | |
$this->createdAt = new \DateTime("now"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment