Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserEditType extends AbstractType{
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $builder
- ->add('roles', EntityType::class, array('multiple'=> true, 'class' => 'AuthBundle:Role', 'choice_label' => 'slug','attr' => array('class'=>'form-control')))
- ->add('email', EmailType::class, array('attr' => array('class'=>'form-control')))
- ->add('username', TextType::class, array('attr' => array('class'=>'form-control')))
- ->add('active', CheckboxType::class, array('attr' => array('class'=>'checkbox')));
- }
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults(array(
- 'data_class' => User::class,
- ));
- }
- }
- /**
- * @ORMTable(name="users")
- * @ORMEntity(repositoryClass="AuthBundleRepositoryUserRepository")
- */
- class User implements AdvancedUserInterface, Serializable
- {
- /**
- * @ORMColumn(type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @ORMColumn(type="string", length=25, unique=true)
- */
- private $username;
- /**
- * @AssertLength(max=4096)
- * @AssertLength(min=8)
- */
- private $plainPassword;
- /**
- * @ORMColumn(type="string", length=64)
- */
- private $password;
- /**
- * @ORMColumn(type="string", length=240, nullable=true)
- */
- private $profilePicture;
- /**
- * @ORMColumn(type="string", length=180, unique=true, options={"default" : "default.png"})
- */
- private $email;
- /**
- * @ORMColumn(name="is_active", type="boolean", options={"default" : 0})
- */
- private $isActive;
- /**
- * @ORMManyToMany(targetEntity="Role")
- * @ORMJoinTable(name="user_role",
- * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id")}
- * )
- *
- * @var ArrayCollection $userRoles
- */
- protected $userRoles;
- public function __construct()
- {
- $this->userRoles = new ArrayCollection();
- }
- public function getUsername()
- {
- return $this->username;
- }
- //deprecated bcrypt does not require salt
- public function getSalt()
- {
- // you *may* need a real salt depending on your encoder
- // see section on salt below
- return null;
- }
- public function isActive()
- {
- return $this->isActive;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function getplainPassword()
- {
- return $this->plainPassword;
- }
- public function getPicture()
- {
- return $this->profilePicture;
- }
- public function getRoles()
- {
- return $this->getUserRoles()->toArray();
- }
- public function eraseCredentials()
- {
- }
- /** @see Serializable::serialize() */
- public function serialize()
- {
- return serialize(array(
- $this->id,
- $this->username,
- $this->password,
- $this->isActive,
- // see section on salt below
- // $this->salt,
- ));
- }
- /** @see Serializable::unserialize() */
- public function unserialize($serialized)
- {
- list (
- $this->id,
- $this->username,
- $this->password,
- $this->isActive,
- // see section on salt below
- // $this->salt
- ) = unserialize($serialized);
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set username
- *
- * @param string $username
- *
- * @return User
- */
- public function setUsername($username)
- {
- $this->username = $username;
- return $this;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return User
- */
- public function setPlainPassword($password)
- {
- $this->plainPassword = $password;
- return $this;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return User
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Set profilePicture
- *
- * @param string $profilePicture
- *
- * @return User
- */
- public function setProfilePicture($profilePicture)
- {
- $this->profilePicture = $profilePicture;
- return $this;
- }
- /**
- * Get profilePicture
- *
- * @return string
- */
- public function getProfilePicture()
- {
- return $this->profilePicture;
- }
- /**
- * Set email
- *
- * @param string $email
- *
- * @return User
- */
- public function setEmail($email)
- {
- $this->email = $email;
- return $this;
- }
- /**
- * Get email
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set isActive
- *
- * @param boolean $isActive
- *
- * @return User
- */
- public function setIsActive($isActive)
- {
- $this->isActive = $isActive;
- return $this;
- }
- /**
- * Get isActive
- *
- * @return boolean
- */
- public function getIsActive()
- {
- return $this->isActive;
- }
- public function isAccountNonExpired()
- {
- return true;
- }
- public function isAccountNonLocked()
- {
- return true;
- }
- public function isCredentialsNonExpired()
- {
- return true;
- }
- public function isEnabled()
- {
- return $this->isActive;
- }
- /**
- * Add userRole
- *
- * @param AuthBundleEntityRole $userRole
- *
- * @return User
- */
- public function addUserRole(AuthBundleEntityRole $userRole)
- {
- $this->userRoles[] = $userRole;
- return $this;
- }
- /**
- * Remove userRole
- *
- * @param AuthBundleEntityRole $userRole
- */
- public function removeUserRole(AuthBundleEntityRole $userRole)
- {
- $this->userRoles->removeElement($userRole);
- }
- /**
- * Get userRoles
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getUserRoles()
- {
- return $this->userRoles;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement