Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. # app/config/security.yml
  2. security:
  3. encoders:
  4. DeliveryAdminBundleEntityUser:
  5. algorithm: bcrypt
  6.  
  7. providers:
  8. our_db_provider:
  9. entity:
  10. class: DeliveryAdminBundle:User
  11. property: username
  12.  
  13. access_control:
  14. - { path: ^/admin, roles: ROLE_USER }
  15.  
  16. firewalls:
  17. main:
  18. pattern: ^/admin
  19. http_basic: ~
  20. provider: our_db_provider
  21.  
  22. <?php
  23. namespace DeliveryAdminBundleEntity;
  24.  
  25. use DoctrineORMMapping as ORM;
  26. use SymfonyComponentSecurityCoreUserUserInterface;
  27.  
  28. /**
  29. * @ORMTable(name="app_users")
  30. * @ORMEntity(repositoryClass="DeliveryAdminBundleRepositoryUserRepository")
  31. */
  32. class User implements UserInterface, Serializable
  33. {
  34. /**
  35. * @ORMColumn(type="integer")
  36. * @ORMId
  37. * @ORMGeneratedValue(strategy="AUTO")
  38. */
  39. private $id;
  40.  
  41. /**
  42. * @ORMColumn(type="string", length=25, unique=true)
  43. */
  44. private $username;
  45.  
  46. /**
  47. * @ORMColumn(type="string", length=64)
  48. */
  49. private $password;
  50.  
  51. /**
  52. * @ORMColumn(type="string", length=60, unique=true)
  53. */
  54. private $email;
  55.  
  56. /**
  57. * @ORMColumn(name="is_active", type="boolean")
  58. */
  59. private $isActive;
  60.  
  61. public function __construct()
  62. {
  63. $this->isActive = true;
  64. // may not be needed, see section on salt below
  65. // $this->salt = md5(uniqid(null, true));
  66. }
  67.  
  68. public function getUsername()
  69. {
  70. return $this->username;
  71. }
  72.  
  73. public function getSalt()
  74. {
  75. // you *may* need a real salt depending on your encoder
  76. // see section on salt below
  77. return null;
  78. }
  79.  
  80. public function getPassword()
  81. {
  82. return $this->password;
  83. }
  84.  
  85. public function getRoles()
  86. {
  87. return array('ROLE_USER');
  88. }
  89.  
  90. public function eraseCredentials()
  91. {
  92. }
  93.  
  94. /** @see Serializable::serialize() */
  95. public function serialize()
  96. {
  97. return serialize(array(
  98. $this->id,
  99. $this->username,
  100. $this->password,
  101. // see section on salt below
  102. // $this->salt,
  103. ));
  104. }
  105.  
  106. /** @see Serializable::unserialize() */
  107. public function unserialize($serialized)
  108. {
  109. list (
  110. $this->id,
  111. $this->username,
  112. $this->password,
  113. // see section on salt below
  114. // $this->salt
  115. ) = unserialize($serialized);
  116. }
  117.  
  118. /**
  119. * Get id
  120. *
  121. * @return integer
  122. */
  123. public function getId()
  124. {
  125. return $this->id;
  126. }
  127.  
  128. /**
  129. * Set username
  130. *
  131. * @param string $username
  132. *
  133. * @return User
  134. */
  135. public function setUsername($username)
  136. {
  137. $this->username = $username;
  138.  
  139. return $this;
  140. }
  141.  
  142. /**
  143. * Set password
  144. *
  145. * @param string $password
  146. *
  147. * @return User
  148. */
  149. public function setPassword($password)
  150. {
  151. if ($password) {
  152. $this->password = password_hash($password, PASSWORD_DEFAULT);
  153. }
  154.  
  155. return $this;
  156. }
  157.  
  158. /**
  159. * Set email
  160. *
  161. * @param string $email
  162. *
  163. * @return User
  164. */
  165. public function setEmail($email)
  166. {
  167. $this->email = $email;
  168.  
  169. return $this;
  170. }
  171.  
  172. /**
  173. * Get email
  174. *
  175. * @return string
  176. */
  177. public function getEmail()
  178. {
  179. return $this->email;
  180. }
  181.  
  182. /**
  183. * Set isActive
  184. *
  185. * @param boolean $isActive
  186. *
  187. * @return User
  188. */
  189. public function setIsActive($isActive)
  190. {
  191. $this->isActive = $isActive;
  192.  
  193. return $this;
  194. }
  195.  
  196. /**
  197. * Get isActive
  198. *
  199. * @return boolean
  200. */
  201. public function getIsActive()
  202. {
  203. return $this->isActive;
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement