Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. class UserEditType extends AbstractType{
  2.  
  3. public function buildForm(FormBuilderInterface $builder, array $options)
  4. {
  5. $builder
  6. ->add('roles', EntityType::class, array('multiple'=> true, 'class' => 'AuthBundle:Role', 'choice_label' => 'slug','attr' => array('class'=>'form-control')))
  7. ->add('email', EmailType::class, array('attr' => array('class'=>'form-control')))
  8. ->add('username', TextType::class, array('attr' => array('class'=>'form-control')))
  9. ->add('active', CheckboxType::class, array('attr' => array('class'=>'checkbox')));
  10. }
  11.  
  12. public function configureOptions(OptionsResolver $resolver)
  13. {
  14. $resolver->setDefaults(array(
  15. 'data_class' => User::class,
  16. ));
  17. }
  18.  
  19. }
  20.  
  21. /**
  22. * @ORMTable(name="users")
  23. * @ORMEntity(repositoryClass="AuthBundleRepositoryUserRepository")
  24. */
  25. class User implements AdvancedUserInterface, Serializable
  26. {
  27. /**
  28. * @ORMColumn(type="integer")
  29. * @ORMId
  30. * @ORMGeneratedValue(strategy="AUTO")
  31. */
  32. private $id;
  33.  
  34. /**
  35. * @ORMColumn(type="string", length=25, unique=true)
  36. */
  37. private $username;
  38.  
  39. /**
  40. * @AssertLength(max=4096)
  41. * @AssertLength(min=8)
  42. */
  43. private $plainPassword;
  44.  
  45. /**
  46. * @ORMColumn(type="string", length=64)
  47. */
  48. private $password;
  49.  
  50. /**
  51. * @ORMColumn(type="string", length=240, nullable=true)
  52. */
  53. private $profilePicture;
  54.  
  55. /**
  56. * @ORMColumn(type="string", length=180, unique=true, options={"default" : "default.png"})
  57. */
  58. private $email;
  59.  
  60. /**
  61. * @ORMColumn(name="is_active", type="boolean", options={"default" : 0})
  62. */
  63. private $isActive;
  64.  
  65. /**
  66. * @ORMManyToMany(targetEntity="Role")
  67. * @ORMJoinTable(name="user_role",
  68. * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
  69. * inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id")}
  70. * )
  71. *
  72. * @var ArrayCollection $userRoles
  73. */
  74. protected $userRoles;
  75.  
  76.  
  77.  
  78. public function __construct()
  79. {
  80. $this->userRoles = new ArrayCollection();
  81.  
  82. }
  83.  
  84. public function getUsername()
  85. {
  86. return $this->username;
  87. }
  88.  
  89. //deprecated bcrypt does not require salt
  90. public function getSalt()
  91. {
  92. // you *may* need a real salt depending on your encoder
  93. // see section on salt below
  94. return null;
  95. }
  96.  
  97. public function isActive()
  98. {
  99. return $this->isActive;
  100. }
  101.  
  102. public function getPassword()
  103. {
  104. return $this->password;
  105. }
  106.  
  107. public function getplainPassword()
  108. {
  109. return $this->plainPassword;
  110. }
  111.  
  112. public function getPicture()
  113. {
  114. return $this->profilePicture;
  115. }
  116.  
  117. public function getRoles()
  118. {
  119. return $this->getUserRoles()->toArray();
  120. }
  121.  
  122. public function eraseCredentials()
  123. {
  124. }
  125.  
  126. /** @see Serializable::serialize() */
  127. public function serialize()
  128. {
  129. return serialize(array(
  130. $this->id,
  131. $this->username,
  132. $this->password,
  133. $this->isActive,
  134. // see section on salt below
  135. // $this->salt,
  136. ));
  137. }
  138.  
  139. /** @see Serializable::unserialize() */
  140. public function unserialize($serialized)
  141. {
  142. list (
  143. $this->id,
  144. $this->username,
  145. $this->password,
  146. $this->isActive,
  147. // see section on salt below
  148. // $this->salt
  149. ) = unserialize($serialized);
  150. }
  151.  
  152. /**
  153. * Get id
  154. *
  155. * @return integer
  156. */
  157. public function getId()
  158. {
  159. return $this->id;
  160. }
  161.  
  162. /**
  163. * Set username
  164. *
  165. * @param string $username
  166. *
  167. * @return User
  168. */
  169. public function setUsername($username)
  170. {
  171. $this->username = $username;
  172.  
  173. return $this;
  174. }
  175.  
  176. /**
  177. * Set password
  178. *
  179. * @param string $password
  180. *
  181. * @return User
  182. */
  183. public function setPlainPassword($password)
  184. {
  185. $this->plainPassword = $password;
  186.  
  187. return $this;
  188. }
  189.  
  190. /**
  191. * Set password
  192. *
  193. * @param string $password
  194. *
  195. * @return User
  196. */
  197. public function setPassword($password)
  198. {
  199. $this->password = $password;
  200.  
  201. return $this;
  202. }
  203.  
  204. /**
  205. * Set profilePicture
  206. *
  207. * @param string $profilePicture
  208. *
  209. * @return User
  210. */
  211. public function setProfilePicture($profilePicture)
  212. {
  213. $this->profilePicture = $profilePicture;
  214.  
  215. return $this;
  216. }
  217.  
  218. /**
  219. * Get profilePicture
  220. *
  221. * @return string
  222. */
  223. public function getProfilePicture()
  224. {
  225. return $this->profilePicture;
  226. }
  227.  
  228. /**
  229. * Set email
  230. *
  231. * @param string $email
  232. *
  233. * @return User
  234. */
  235. public function setEmail($email)
  236. {
  237. $this->email = $email;
  238.  
  239. return $this;
  240. }
  241.  
  242. /**
  243. * Get email
  244. *
  245. * @return string
  246. */
  247. public function getEmail()
  248. {
  249. return $this->email;
  250. }
  251.  
  252. /**
  253. * Set isActive
  254. *
  255. * @param boolean $isActive
  256. *
  257. * @return User
  258. */
  259. public function setIsActive($isActive)
  260. {
  261. $this->isActive = $isActive;
  262.  
  263. return $this;
  264. }
  265.  
  266. /**
  267. * Get isActive
  268. *
  269. * @return boolean
  270. */
  271. public function getIsActive()
  272. {
  273. return $this->isActive;
  274. }
  275.  
  276. public function isAccountNonExpired()
  277. {
  278. return true;
  279. }
  280.  
  281. public function isAccountNonLocked()
  282. {
  283. return true;
  284. }
  285.  
  286. public function isCredentialsNonExpired()
  287. {
  288. return true;
  289. }
  290.  
  291. public function isEnabled()
  292. {
  293. return $this->isActive;
  294. }
  295.  
  296. /**
  297. * Add userRole
  298. *
  299. * @param AuthBundleEntityRole $userRole
  300. *
  301. * @return User
  302. */
  303. public function addUserRole(AuthBundleEntityRole $userRole)
  304. {
  305. $this->userRoles[] = $userRole;
  306.  
  307. return $this;
  308. }
  309.  
  310. /**
  311. * Remove userRole
  312. *
  313. * @param AuthBundleEntityRole $userRole
  314. */
  315. public function removeUserRole(AuthBundleEntityRole $userRole)
  316. {
  317. $this->userRoles->removeElement($userRole);
  318. }
  319.  
  320. /**
  321. * Get userRoles
  322. *
  323. * @return DoctrineCommonCollectionsCollection
  324. */
  325. public function getUserRoles()
  326. {
  327. return $this->userRoles;
  328. }
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement